Free JqGrid: Sort DESC on first click - jqgrid

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.

Related

jsGrid - get data typed by the user in a search navGrid

I'm trying to bind a table and a graph using d3 and jqGrid library. For that I have to get the search typed by the user in the searchbox (my table looks like this : http://www.guriddo.net/demo/guriddojs/)
I've found this function :
grid.getGridParam("postData").filters
but I don't know how to use it. I thought about the trigger event "jqGridToolbarAfterSearch" to get the data after each search but doesn't seems to work...
If someone has an idea I'll be very grateful!
Thanks.
Ps : if the same method exist to set data, I'm interested too.
I hope that I correctly understand your problem. I suppose that you first converts the CSV data of the demo to some more continent data format: array of items with some properties (name, economy, cylinders, displacement, power, weight, mph, year). Then you can use datatype: "local" and data as the input data. I suppose that the user apply the local filter and then you want to get the filtered data
If you use free jqGrid fork of jqGrid (it's the fork which I develop) then you can get lastSelectedData parameter (var filteredData = $grid.jqGrid("getGridParam", "lastSelectedData");) to have the array of filtered items (see the demo). After that you can use d3 with the filtered items.

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.

JqGrid Adding extra parameter to server on sorting

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.

JQ Grid sorting integers

Can anyone please tell me how to sort integers/numbers in JQ grid.
the regular sorting gives a distorted order.
Hi i got it all done when i use loadonce=true and sorttype = 'int'. But i cant use loadonce, since i need to reload the grid several times for my purpose.
Can anyone say how to do it without using loadonce??
Thanks,
Devan
If you use datatype:'json' or datatype:'xml', then the server is responsible for the data sorting. The sidx and the sord parameters which will be send as the part of request to the server describes which sorting should use the server.
If you want to implement client side sorting and paging of data you can use loadonce:true jqGrid parameter. In the case you should define sorttype property (having default value 'text') which describes the data type from the column. After the first data loading the datatype of the jqGrid will be automatically changed to 'local' and the sorting, paging and filtering/searching of data will be implemented locally by jqGrid itself.

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