Get page number of a specific record - jqgrid

I'm trying to find a way to get the page number of a specific record.
This is my problem, after I add a new line I reload the grid, with sorting on, the new line can end up on any page. I need to be able to find the page number of that specific record, so I can navigate to its page and select it.
How can I do that, without having to load every page until I find it.

As I see to to accomplish where you would add a new record, reload the grid and then have that displayed page be the page where the new record would be found in a sorted grid. As a solution I think you would need to set the reloadAfterSubmit: false, and then generate your own reload where you would pass in (via postData) a value that would tell your controller to change the page of data to return to the jqGrid.
When the controller would receive a value in this field you would have to write some code to find which page of data the record would belong to and then pass that page to the jqGrid.
As the grid would be sorted, you could find where where that record would be in the sorted dataset and then grab that page. If you didn't have a very large dataset you could just iterate through every page till you found the page that would contain your result, but the method would depend on how large of dataset you would have. (Ex 5 pages of records, probably acceptable to just iterate through them all, as the dataset becomes larger you will have to look into fetching the proper page of data.)

Related

Extjs- Grid column headers refresh for every search

I am trying to sort my results grid based on a default column header every time the results gets displayed. I tried giving a sorter to the store and it worked fine when the page loads first time. Its working as I want it to be. But the problem arises only when I try to click on a different column header in the grid. When I click on a different header it sorts based on that particular column values. If I click on search button at this point of time without reloading the page, the search results get displayed and are sorted based on my previous selected column. I want this to be sorted based on the default column. Problem is the grid gets refreshed with search results every time I click on search or reset buttons but the column headers are not getting refreshed. So the results are getting sorted based on my previous selection. To fix this problem, I am trying to reload the whole page every time I click on search or reset. Is there a way that I can refresh the column headers along with the search results every time I click on the search so that the results get sorted based on the default column header. I am able to refresh the search results and the pagination part for every search but not the column headers. Any solution...
Thanks....
One thing you didn't mention is whether you really want to allow the user to sort by different columns.
You can switch this behaviour off in the columns definition using sortable: false
http://docs.sencha.com/extjs/4.2.2/#!/api/Ext.grid.column.Column-cfg-sortable
If you want to keep that behaviour, you can replace the sorters with the default one again on every load:
var myDefaultSorter=Ext.create('Ext.util.Sorter',{
property:"MyProperty",
direction:"ASC"
});
store.on('beforeload',function(store) {
store.sorters.clear();
store.sorters.add(myDefaultSorter);
}
Have you tried store.sorters.clear() ?

How magento maintain grid values

I want to know where and how does magneto store the data to maintain grid filter and mode type. Like I go to listing page and select list mode while displaying five records and then goes to other page of the same site and comeback. It shows me my previous grid mode and records. I display $_REQUEST, but doesn't see anything there. Anyone knows how I can get those values?
Magento store limit,order,direction in Mage::getSingleton('catalog/session').
If limit,order,direction is found in REQUEST then new value is set in Mage::getSingleton('catalog/session') .
You can check getLimit(),getCurrentMode(),getCurrentOrder(),getCurrentDirection() function in the class
app\code\core\Mage\Catalog\Block\Product\List\Toolbar.php

COLDFUSION CFGRID Datapass with a post

I have a bit of a unique challenge today. I have a client that wants to be able to search for multiple items based on inserts into a cfgrid. Suppose we have the following web form:
A Country selection dropdown
A State Selection dependent AJAX dropdown
A city Selection dependent AJAX dropdown
An ADD Button
----------------------------------------------------
A CFGRID that will populate a row with selections when the user clicks the add button
----------------------------------------------------
And finally, a CLEAR button, and a GO button on the bottom.
The resulting page will then query the database and get some statistics about the cities selected. So, suppose an individual picks USA > Arizona > Scottsdale and USA > Arizona > Flagstaff. The grid below the options will 'save' each selection and reset to their default options, waiting for a user to pick additional options or click on 'GO'.
The resulting page will then generate columns that list some statistics about the communities and highlight the 'best of' between each selected community.
Each time a user selects the ADD button (assuming three criteria are selected) I want the information to be added into a CFGRID that displays the options selected. Then, After the user selects at least one country/city/state option, have all of the data in the CFGRID get passed to another page that does a query from the data selected. In theory, the user could pick as many communities as they want, assuming they are willing to let the database sludge through enough data to get what they want and wait through a 'loading' screen to get it.
I'm having these challenges, in no particular order:
- I have an HTML grid that I must use per client spec (No Java or Flash, must be HTML)
- I have no idea how to get the selected options into the CFGRID. I assume there is some JavaScript I can write that uses some sort of AddRow function to add data into the grid with the add button but cannot seem to find how to it on the interwebs
- After we conquer the above challenge, how do I pass the data from the grid into the results page? I thought about passing one big string or a structure, but I'm not sure how to do that through the URL or posting, nor how to get the data out of the grid. I wonder if I am better off coding some sort of string that gets passed from the options page to the results page with a get method instead of dealing with the stuff in the CFGRID and have the CFGRID serve only as a 'dummy' display container.
- Finally, after the pass is complete, I would need to loop through through the structure and perform a CFQUERY or CFSTOREDPROC on each row of data, then get the statistics I need to display on the results page. I assume this would depend on how I am getting the data from the options selection page to the results page.
THANK YOU ALL!
CFGRID is great to start, but it can be b*tch to customize and extend... Have you tried editable CFGRID with bind? See how far off it is from what you want first. If it turns out to be very far, then you might want to go for a jqGrid and code up some jQuery.
To start, read Using HTML grids and make the cfgrid editable.
http://help.adobe.com/en_US/ColdFusion/9.0/Developing/WSc3ff6d0ea77859461172e0811cbec22c24-7a01.html#WSc3ff6d0ea77859461172e0811cbec22c24-72e0
Once you got that working, look at these provided JS functions that you can use with CFGRID
http://help.adobe.com/en_US/ColdFusion/9.0/CFMLRef/WS0ef8c004658c1089-6262c847120f1a3b244-8000.html
http://help.adobe.com/en_US/ColdFusion/9.0/CFMLRef/WSd160b5fdf5100e8f-4439fdac128193edfd6-7f5f.html
If you still demand a bit more, you might need to dig into the underlying ExtJS component. At that point I would rather use jqGrid
I found out that the best way to handle this was by using a SerializeJSON call and a Deserialize JSON call back and forth. By using JavaScript notation we are able to pass a complex JavaScript object (array) between one page and another. This has the value add of not having to worry about sessions timing out and making URLs clickable from one solution to the next.

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

Resources