jqGrid - ambiguous npage parameter from prmNames property - jqgrid

I'm using jqGrid to load data with virtual scrolling. It is working ok, but I'm also trying to make it load some data ahead, at least one page ahead, to avoid the loading appearing while the user is scrolling. In documentation, the npage parameter is the one specified to handle this. I assigned boolean values to it, int values from 1 to 100, but doesn't have any effect. What am I missing?
If you set the npage option in prmNames, then the grid will sometimes
request more than one page at a time; if not, it will just perform
multiple GET requests.
jqGrid Docs
demo virtual scrolling-npage is set to null

You have misunderstood the documentation a little bit. You need to set the npage property of prmNames object to a string, for example like this:
prmNames: {
npage: 'npage'
}
This will tell jqGrid that when dynamic scrolling is enabled (the value of scroll option is different than False) it can (at own will so not always) request more than one page by adding the number of pages it want to the request under the key by name which you have specified in npage property.

Related

YUI DataTable Changing DraggableColumn and Resizable

After a YUI2 datatable is constructed, is it possible to change configuration settings dynamically?
If draggableColumns was not set true when the datatable was initialized, how can I change that behavior later on?
Similarly, when columns are not identifed as resizable, is there a way to change it later?
I expected a datatable method would allow this to happen (set on/off), but I can't seem to find something like that in the API (http://developer.yahoo.com/yui/docs/module_datatable.html).
So, I tried browsing the datatable object and changing each column's 'draggable' flag. That didn't work and it also didn't seem the right way to do it.
How can I do this?
Every element's configuration object can be accessed via it's cfg attribute.
So, in order to set draggableColumns config property dynamically, you need to use :
myDatatable.cfg.setProperty("draggableColumns", "true", true)
Note that the second boolean argument should be a string. Refer this link for reference.

Client side paging on Jqgrid?

could anyone tell me how to implement client side paging on jqgrid?
Currently, my pager just shows one page which is an error. However, if I change the number of records per page using the drop down, the grid is updated accordingly. But I am unable to navigate thru the pages.
Thanks in advance
I suppose that you fill the grid in the wrong way. You don't included any code in your question, so I can only guess that you use addRowData method to fill the grid. If it's so, then you should know that the usage of addRowData method it the worst and the slowest way to fill the grid which I know.
The best way in case of datatype: 'local' is to use data option of jqGrid in combination with gridview: true. It sorts the data from the data parameter corresponds with sortname and sortorder options, create jqGrid and display the first page of the grid (the size of the page defines rowNum option). The value of data parameter should be array of items which represent the grid rows. Every item should contains properties with the names like the name property of colModel. Additionally every item of data should contains id property which unique value will be used as id attribute of rows (id of <tr> elements).

JqGrid setting the last page for datatype local

I have a Jqgrid which has datatype as local. I am loading data at run time using addRowData, setCell. Every thing is working great. Note that I am not loading the entire data into grid so grid does not know how many pages are there. My server returns the count which I need to set it to the grid. The docs say that lastpage is ReadOnly? How do I set my last page(number of pages) to the grid? Any suggestions.
Thanks,
Sarath
The usage of addRowData method to fill jqGrid is the most old and the most ineffective way to fill the data in jqGrid. The problem is easy. If you place an element on the page the position of all other elements on the page have to be recalculated. It makes many resources of the web browser. The filling of the whole jqGrid body in one step is much more effectively especially with the large number of inserted rows. It's really needed to use addRowData method only in seldom cases.
Much more effective will be to use data parameter of jqGrid which allows to fill the grid with the data, sort the data corresponds to sortname and sortorder and display the first page where rowNum defines the number of rows per page. Additionally one should not use afterInsertRow callback and use gridview: true. In the case the filling of jqGrid is the most effective.
The number of pages of the grid will be calculated automatically based on the number of rows in the grid. Only if you use server side datatype ('json' or 'xml') the client part don't know the total number of pages and so one have to fill in the input data total, page and records together with the main data (see documentation). If one uses low level method addJSONData one can fill grid with the data and still set total, page and records to any values which you want.
Another way which you can use in some scenarios is datatype: 'jsonstring'. The data can be placed as the value of datastr option. By the way the value of datastr must be not only the JSON string but can be an object too.

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

Is it possible to dynamically change the page size in a YUI Paginated Datatable?

I have a YUI Datatable which is paginated. The height the datatable is able to use can change. What I want to happen is that when there is a size change (which I already have a handle on), I can take the new height and find how many rows are going to fit in a page, then change the datatable or it's paginator to have that number of rows.
Is this something that is possible with YUI Datables, if so is there examples or documentation about it?
myDataTable.get('paginator').setRowsPerPage(25);
It appears that if you can get a reference to the YAHOO.widget.Paginator instance, you can call:
theTablesPaginator.setRowsPerPage(numRows, silent)
Where the silent option allows setting whether the changeRequest event should be sent. If you wish the datatable to redrawn, set this to false.
Reference: the very useful official YUI documentation

Resources