JqGrid Adding extra parameter to server on sorting - jqgrid

I would like to know if there is a way to add extra parameters to the sort call. When I click on a jQGrid column in order to sort (asc or desc) a row, I would like to know if there is a way to add extra parameters in order to be able to customize my order on server side basing in passed parameters. Because, every time I click to order by a column, when I reach the server I dont know if the call is from a sort event or from a load event, and I have to know it to make diferents querys.
thanks

You can use the onSortCol event to modify the postdata of the grid to send an additional flag
Alternatively, you know the default sort column and sort order that you set in the grid object. You could just check in the backend to see if the sidx and sort parameters are different from the defaults.

Related

Free JqGrid: Sort DESC on first click

I'm using Free JqGrid and I have an issue with sorting the columns. I use a remote data in my setup. I want the grid to load default without no sorting at all, but when the user clicks any of the sortable columns I want it to sort DESC first instead of ASC (which it will always do). I'd also like the (default) sorting icons to point in this direction.
Can anyone point me in the right direction?
If you use remote datatype (datatype: "json" or datatype: "xml") then the data will be displayed in the grid in the order in which it will be returned from the server. If your server sort the data based on the request from jqGrid then you need verify that you use no initial sortname parameter.
About your second problem. It's enough to add firstsortorder: "desc" property to the column definition to have DESC sort order on the first click of the user on the column header.

Sorting on hidden data

Is it possible to have data in a Handsontable sorted by a field which is not displayed? I have a grid of data which I would like to display that contains a column called "sortOrder", but I don't want to display this.
The sorting needs to be done client side because events are coming in over web sockets and need to be reflected in the table.
If you're not showing the column then I assume you're not expecting the user to be able to manually sort by this hidden column. Therefore, why don't you simply sort your data array with native JS? At any point during execution you could have a function which sorts by this hidden column and then just don't render this in your Handson definition.
So yes, the answer is it is possible. The not showing of a column is as simple as defining the columns option and not including a column for this hidden value.

Sort whole store in paging grid extjs 4

in my app I have a paging grid and when I click on a column to sort it, it sorts only the current page. How can I sort the whole store and then split it in pages?
Can I override the sort function to send extra params to the php script that convert my database into a json store and edit the query adding a ORDER BY extraparam?
You need to enable remoteSort by setting remoteSort: true on the store instance. See remoteSort
You will now receive the sorting as you receive the paging as own params-list and can include it into your query.

Date Ranges in jqGrid Searches

We are using advanced search in the latest version of jqGrid, and our search dialog is configured to be always visible on the page above the grid. The structure of our data lists is dynamic. Thus, when we are going to display a list, we first do an ajax call to get the list of columns for the grid. We then construct the data model for the grid and make a request for the data.
Currently, in the request to get the columns, we return the data type of the column. If the data is a date, we display a date picker in the search form. However, some of our customers HATE having to use <= >= for date ranges. They want to be able to pick a date column and then set a start and end date using two side-by-side date pickers. I've been pushing them off for a while now because they have the ability to do date range searches, but the complaining isn't stopping. (It's more clicks to add the second filter with the end date)
Is there any way I can modify jqGrid to give me a date range control when I am configuring a search on a date column? I really don't want to have to set up an external search dialog UI just to deal with these complaints, but product-management is pushing really hard to get "normal" date ranges for the grids.
You can create your own custom search dialog. See this question which I asked couple days ago.
using setGridParam to change your postData array and include extra values in the filters JSON object that will be carried over to your server side where you can dissect it. In your case you can pass over your data range Start and End inside the filter item of the postData. Then reload your jqGrid like this
var $grid = $("#list');
//$grid.setGridParam({datatype:'json', page:1}).trigger('reloadGrid');
var post_data = {searchField:'',searchString:'', searchOper:'',
filters:'{"groupOp":"OR","rules":['+
'{"field":"Date","op":"ge","data":"2012-04-23"},'+
'{"field":"Date","op":"lt","data":"2012-04-25"}' +
']}'
};
$grid.setGridParam({postData:post_data}).trigger('reloadGrid');
The above will save the postData array with the new config and the reloadGrid sends a request to the server with the new postData array. This will preserve the paging as well; however, to get the old view of your grid (without search terms) you need to implement the reset button separately too and trigger reloadGrid after that for this to take effect.
Not sure if you have solved your problem by now; however, I am putting this solution here for any one from the future who has the same issue.
As far I know there is no way to do this, but to write it yourself.
http://www.trirand.com/jqgridwiki/doku.php?id=wiki:custom_searching
Filter jqGrid Data by Date Range?

Filter Toolbar without loadonce:true?

I am using jqgrid, with filter toolbar(column) option...The total data is around 10,000...So it seems to be some delay in initial loading as the config is set to loadonce:true;
Any way to implement the filter column feature with loadonce:false ?
Because the data loading delay is okay with loadonce:false. If I get a chance to add column filter with loadonce:false, this will work perfectly...
If you has about 10,000 rows it is of course better to implement server side data paging, sorting and filtering. I recommend you to use filterToolbar with the parameter stringResult:true if you not already use it. In the case jqGrid will send to the server filters parameter in the same format like advanced searching as do. So you will need implement on the server side the method which use following input parameter from jqGrid:
sidx and sord parameters define the sort order of the data. The informations specify ORDER BY in the corresponding SELECT statement.
if _search parameter is true, then the next parameter filters gives additional information which construct the WHERE part of the corresponding SELECT statement.
page and rows parameters define which page of the data previously sorted and filtered should be returned.
The exact implementation is depend on the language and technology which you use on the server and of course which database server and which interface to the database you use.

Resources