jqGrid editurl value for local editing? - jqgrid

I have a jqGrid set up with local data. I'm not sending any data to the server until the entire form is filled out. My problem is, when a user adds/edits a row, jqGrid attempts to post the results to the server right then.
I tried leaving out the "editurl" attribute from the jqGrid invocation, but this results in a "No URL is set" error when the user clicks the "submit" button on the popup form for adding/editing records.
I tried putting in a single hash "#" for the editurl value, but this also fails.
Any thoughts?

editurl must be 'clientArray' in your case.

Set editurl:'url', cellsubmit:'clientArray', cellEdit: true
or
here

See this for a complete example of jqgrid local data.
local edit on jqgrid
Change your initial data and your columnmodel, and you will be almost done.
It's not a oneline solution, but, seems this is the way to cope local editing.

Related

need to get filters and sorting behavior from jqgrid for a different hidden field

I have a form on my page that is submitting independently of the jqgrid. I need to get any filters and the sorting behavior of the grid as it is currently loaded on the client and include that in my post data that I'm sending up to the server so that it can perform what it needs to perform using the same searching criteria.
I tried this to no avail:
$("#settings").val($("#list").getGridParam("postData"));
where settings is the id of a hidden field in my form. It does indeed pass in the gridsettings object to back end, but it's not including any of my filters and sorting behavior.
any suggestions?
EDIT: when I do console.log($("#settings").val()); in firefox it's showing the correct filters and searching criteria. I'm using the same object on the back end that I do for the actual grid and it's just not working. Do I need to change that object somehow since I'm posting this through a regular http post and not an ajax postback?
EDIT 2: if you read the comments under Oleg's post, you'll see how I resolved this. I had to pass each property separately that is held within the object created by getGridParam(). I am marking his answer as the correct answer as his comments lead me down the right path.
I suppose that you could solve the problem by adding
searchoptions: {searchhidden: true}
for hidden columns in colModel which can be used during searching. If you want to set the settings for all columns you can use cmTemplate option of jqGrid:
cmTemplate: {searchoptions: {searchhidden: true}}
See the answer for more details about cmTemplate.

Post non editable values in jqGrid?

I'm using jqGrid, and I would like to post non editable values to the server. I'm editing row by row (not form). Is that possible?
The column is visible, and I'm using inline editing. The data is posted using "editurl" property of the grid.
** Solution **
I solved it in a completely different way, by not using jqGrids setCell, but instead setting the textbox value using document.getElementById(selr + "_Verksamhetskod").value = data.
Not exactly what I had in mind initially, but it works...
Just add that to your cell configuration:
editable: true, editoptions: {disabled: true}
Well if I'm understanding correctly you are trying to make a cell become read-only once it has a value but still be in a format where you can post to the server correctly.
You could use Jquery to place a read-only attribute on each input field
$("#PrimaryKey".columnName").attr("disabled", true)
and either fire this code if there is a value in the input field or after an input has been entered.

Is there any way to keep current page when sorting jqgrid columns?

My jqgrid contains several pages. When I sort any column the page resets to first.
(That's right also for filterToolbar i.e. after calling $("#my-grid")[0].triggerToolbar();)
Is there any way to keep my current page after sorting/filtering ?
EDIT:
Actually my problem is a little more complicated.
I save jqgrid preferences(rowNum, page, filters etc..) to the cookie.
When I load the page first time I load the prefs.
I use the technique from Mark B's answer (see jqGrid Filter Toolbar initial default value) to populate my filter default values.
The problem: in that case page always sets to the first.(because of triggerToolbar calling) i.e. it doesn't save state.
I don't quite understand your requirement. If the user has seen some rows on the second page for example and then the user has clicked on the column header to sort the column the the grid will be sorted. The data which the user have seen before can be on any page. So I don't understand why you want hold the current page which will show absolutely another data as it showed before.
If you do need to hold the page you can do this in the following way. Inside of the loadComplete you can save the value of page parameter. Inside of onSortCol event handler the value will be already changed to 1, but you can correct it to the value which you saved before. I didn't tested this, but I think it should work.
UPDATED: Now I think I understand your original problem. I think you should choose another way described here or here. What you needs is just to save in the cookie the postData value and to set search:true parameter of jqGrid if the filters is not empty (or other filter parameter depend on the options which you use). In the way you should be able to restore not only the filter, but additionally the page value. The final solution can a little depend from jqGrid parameters and the parameters of filterToolbar which you use. So it you will have implementation problem you should include more code which you use.
I'm using mvc with jqgrid and this solition work for me:
$("#GridTable").jqGrid({
...
onSortCol:
function () {
var postpage = jQuery("#GridTable").getGridParam('postData');
jQuery("#GridTable").setGridParam({ page: postpage.page });
},
...
});

jqgrid click local data column sort (client-side only) wipes userData on grid refresh

I have a grid that is populated by a JSON response (MVC3 controller) that has a userData component for some additional data for grid captions, etc. All that works just fine. I recently switched the the grid's data loading to "loadonce: true" as in working with larger grid results sets, I wanted client-side sorting and filtering. All that works good. BUT, I was surprised that the userData got wiped the first time I clicked any column for sorting. If I turn off loadonce, userData is fine, but it is of course going back to the server each time. The items that make use of the userData fire on gridcomplete and are now coming back "undefined" after a sort (and probably anything that reloads the grid). Any thoughts why this might be happening? Oh yeah, I also noticed that clicking a column sort wiped out any multiselections (perhaps related to the same culprit?).
Thanks,
Mark
You are right. +1 from me. It's a jqGrid bug. Inside of internal addLocalData method after the line 1527 of the file grid.base.js of jqGrid 4.1.2 or after the 1532 of jquery.jqGrid.src.js (you can get modified version from here) one should add the following line
retresult[ts.p.localReader.userdata] = ts.p.userData;
It will fix the problem. I posted the corresponding bug report here.

using jqGrid addJSONData function with scroll and loadonce option at same time

in my web application i am already using jqgrid since version 3.5.
at my application such as search window, page is comming with no date. after user entering seach parameter when clicking search buton i have done request, grid data and other variable that i needed has come with this ajax request.
so i populate grid with addJSONData metod such as ;
var data = {"page":"1″,"total":0,"records":0,"rows":[{"id":"1","cell":["1-480","1884","BASYAYLA"]},{"id":"2″,"cell":["2-481","1983","SARIVELILER"]}]};
// data variable has return from ajax request.
var mygrid = jQuery("#mygrid")[0];
mygrid.addJSONData(data);
Grid populating is problem when you working with big data set. Yesterday i seen new properties called scroll and loadonce at demo page.
I understand that when i use datatype except than json.
i try to use these metod but i am not able to success.
How could i use addJSONData, scroll and loadonce at same time.
i find solution myself
when you are using loadonce metod it will turn datatype to local so addJSONData metod dont work because datatype is not json.
by following these steps, problem has solved.
i set datatype local to grid dont make first call
$.extend($.jgrid.defaults,{
datatype: "local"
});
for loading data to grid. i follow these commands;
$("#"+objeId).setGridParam({datatype:'json', loadonce:true});
mygrid.addJSONData(myjsongrid);
$("#"+objeId).setGridParam({datatype:'local'});
every thing work fine for me.

Resources