Is there a way to remove all the rows in the jqGrid, without calling jqgrid's loadComplete method.
You can use clearGridData. From the jqGrid documentation:
Clears the currently loaded data from grid. If the clearfooter parameter is set to true, the method clears the data placed on the footer row.
A quick inspection of the code seems to confirm that this method does not call loadComplete, although it will call gridComplete.
Related
I want to trigger a function after the user search something on my navGrid.
I've found the event loadComplete but that doesn't match with my expectations because I also reload my grid programmatically. Then maybe there is something link to the click... if someone has an idea.
Thanks.
There are exist onSearch callback (and jqGridFilterSearch jQuery event). It trigger reloadGrid which finish with loadComplete (and jqGridAfterLoadComplete jQuery event). You can set some custom option of jqGrid inside of onSearch callback (for example, $(this).jqGrid("getGridParam").searchingStarted = true;) and to test its value inside of loadComplete. At the end of loadComplete you should always reset the value of the custom option. In the way you can distinguish reloading of the grid started from Searching Dialog from other reloading.
I have a grid, to which I'm making a delRowData(rowId) call to, whenever the grid gets reloaded using .trigger('reloadGrid') the deleted row returns, I can access the grid data and delete it from there, but I'd prefer not to, if I can avoid it.
To note, I need to reload the grid as I have custom subgrid tabs that get out of alignment when the row is deleted. The row also returns when I change pages on jqgrid's pagination.
Any suggestions?
.delRowData() function only deletes the row from clientslide if you don't use datatype: "local", once you trigger grid reload, it will get the data again from the server to fill your grid. So you can first delete the row on your server side, then in the jquery.ajax callback function you can invoke .delRowData() or some other function like this.
I want to remove the pointer cursor from all non-sortable column headers in all of my jqGrids as in this answer. I currently do so for some of them in the gridComplete event.
Is there a way to set a default event, or grab all of the jqGrids on a page, and append that function the gridComplete event? I could not find anything in the options.
If you don't change the value of sortable property of the columns dynamically you don't need to do this on every grid refreshing. The columns will be created once at the creating of jqGrid. So you can just place the code which fixes the cursor on non-sortable columns after the grid definition. So you don't need to use gridComplete or any other callback.
By the way I use the word "callback" instead of "event" used in jqGrid documentation because you can define really one callback per grid. So you can't easy define somewhere in common place gridComplete with common actions and use another gridComplete in the grid definition. So if you define gridComplete as default option $.jgrid.defaults (see here) it will default till you not overwrite it in the definition of some jqGrid. To fix the problem I posted detailed suggestion how to extend functionality of jqGrid to support real events. Later I posted pull request with the changes. After long discussion the functionality is included in the code of jqGrid. So the next version jqGrid (which should be published in a short time) will do have support events additionally to callbacks.
Does anybody know how adding a jqGrid pager after grid creation using 'tableToGrid' function?
jqGrid uses internally the setPager function to make the most work for creating of the pager. The function setPager is local and can't be called from the outside.
If you need have in some situation the pager I would recommend you to create it always, but hide with respect of $('#pager').hide() till the pager will be needed. The grid with hidden pager looks exactly like the grid without pager.
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 });
},
...
});