Attach method to all jqgrid instances? - jqgrid

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.

Related

Filter every character in Kendo Grid

How do you force a Kendo grid to filter data after every character is typed, as in after every letter, not just when I press enter button?
I noticed that Kendo sends requests after every character typed, but without page size, and this request is used for autocomplete. I want to change that to bind this data not to autocomplete, but to the main grid instead.
I am using built in filters, one for each column.
Sorry for later response, I didn't have much time. Anyway as I mentioned in comment, this functionallity is not supported by Telerik. So you have to create everything by yourself.
In following example I have used filterMenuInit event which is fired after you click on filter icon (and only once!). In that event I have modified filter elements to add custom classes and ids. Then in jQuery I am catching keyUp events and adding items into filter.
Here is small example. I have implemented only equals filter, so you will have to do some modifications. But I hope it can help you in next work.

jqGrid How to remove all rows without calling loadComplete

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.

Adding a jqGrid pager after Grid creation

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.

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 });
},
...
});

integration of star ranking plugins into jqgrid

hast anybody already integrated a star ranking plugin (eg. http://www.wbotelhos.com/raty/) into jqgrid? What is the best way to do this?
Thanks
Anatoliy
When I have done custom cells, I have either hooked into one of the grid events (afterInsertRow) or if using gridview:true then gridComplete or loadComplete.
Then simply use the setCell method to insert the html into the row.

Resources