How to: jqGrid dependent select box display values in rows - jqgrid

I have implemented dependent dropdowns in jqGrid (similar to this example). The row data returned has values as well as display values. How can I show display values on grid rows? At grid initialization time I do not have list of values for dependent dropdowns, they get loaded from the server when user selects value from other dropdown. formatter: 'select' helps when I know the values of dependent dropdown but I am not sure how to use it when the values are loaded dynamically.

In case of loading the data from the server you need just set editoptions.value or formatoptions.value before formatter: "select" start to process the data. You can use beforeProcessing callback for example. It will be called at the moment which you need. You can place the information with editoptions.value in userdata part of the server response or in any other place. The data parameter (the first parameter) of beforeProcessing callback contains all the data from the server response. So you can easy get the required data and to use setColProp for example to change the options used by formatter: "select". I recommend you to read the answer for the corresponding code example.

Related

Why is free-jqgrid not resetting row ids after GridUnload?

The Problem
I have a very complex, rather outdated jqgrid implementation that I'm upgrading to the latest free-jqgrid and we're having an issue in that after clearing the grid with unload, when we re-initialize the grid, the row ids are higher than they should be to start.
They seem to still be incrementing and not starting again. Are there some global counters I need to clear out to have the grid completely clear itself before we re-render it?
Grid Clear
if ( this.timesheet_grid ) {
this.timesheet_grid.grid.jqGrid( 'GridUnload' );
this.timesheet_grid.grid = null;
this.timesheet_grid = null;
Rows after GridUnload has been run
Shows an id like jqg56
Stuff I've Tried Since Posting
GridDestroy
clearGridBeforeUnload
SOLUTION
As #Oleg has suggested i simply needed to set the id attribute manually when processing the grid data.
I see that your incorrectly understand the meaning of rowids and the requirements for input data. I'm wonder especially about the suggestion of Tony to reset $.jgrid.guid. I find the suggestion very bad because it looks like a solution, but it can produce more seriously problems as the problems, which are solved!
First of all, it's important to understand what is rowid. Rowid is the values of id attribute of the grid rows: the id values of <tr> elements of the grid's body (see here). The rowid are used as a parameter of almost all callbacks and events of jqGrid. Because of that jqGrid must assign id attribute to every row and the input data of the grid have to contain rowid information! The existence of rowids is critical for working jqGrid. Only because of that jqGrid generates unique rowids in case of wrong input data. Alternative for generation of ids would be preventing creating the grid at all.
jqGrid tolerates the error with specifying the rowids in input data only for some simple grids, where one need just display some simple data and one never need to use rowids. If you use ids then you should fix the problem only in one way: you have to fix your input data. You can for example include id property with unique value in every element of input data. You should take in consideration that no id duplicates exist not only in the grid but on the whole HTML page. It's strictly recommended to use idPrefix option with unique value for every grid always if your HTML page have more as one grids (inclusive grid with subgrids).
Resetting of $.jgrid.guid is very dangerous and it can break functionality of jqGrid because of creating elements with duplicate id values. The property $.jgrid.guid is global. It's common over all grids and subgrids on the page. Simple subgrids scenario will produces id duplicates after you manually reset $.jgrid.guid. It will be used inside of $.jgrid.randId() method used in many places of jqGrid code. For example, the method addRow used by inlineNav uses the method.
I repeat my suggestion more clear once more. If you uses rowids or if the values of rowids are important for you in some way then you have to include id property to every item of input data. If some other property has already an unique value then you can add key: true in the corresponding column of colModel (one can use key: true in only one column). Alternatively, you can add prmNames: { id: "myId" } if myId property of input data contains unique rowid instead of default id property.
jqGrid uses common counter in order to be a sure that there will be no duplicate values when a build in id generator is used.
To reset the value you will need to set the guid parameter to 1 - i.e
$.jgrid.guid =1;
after you unload the grid
If the solution is based on the knowing the behavior of the product, then this is a good solution.
If we try to solve the problem, without to knowing the behavior - it is a dangerous solution.
It is very easy to say - this is bad solution and it is very very dangerous to use this solution - so my question is:
What is happen with the counter if the user reload the page under some conditions?
The answer is: the counter is reset and we go to the same situations which are described in the above answer.

GWT (smartgwt) grid sort selected records top

I have a grid where the user can select records via checkbox in front of every record. Now I have a requirement to sort the records based on their selection, so that all selected records should be placed top, followed by the not selected ones.
Is there any standard function to achieve this? As an alternative I thought of saving the selection state as an attribute on every record and sort based on the attribute.
The code for the column is:
gridRealmDt.setSelectionType(SelectionStyle.SIMPLE);
gridRealmDt.setSelectionAppearance(SelectionAppearance.CHECKBOX);
I try to describe the code I use as the affected code is deeply nested in our own framework classes.
gridRealmDt is a subclass of smartgwt ListGrid. In my Dialog a create an instance of the grid which creates an instance of a database bound datasource. When the dialog is loaded the records are fetched from the database and after that a registered an dataArrivedHandler where I select the records which match records from another table.
I tried to place the selection attribute in an extra field and use that for sortig before my other sort criteria, but this does not work. Here is the code for the field I am using.
ListGridField txtSelected = new ListGridField(SELECTED, "");
txtSelected.setHidden(true);
txtSelected.setSortByDisplayField(true);
txtSelected.setCanSortClientOnly(true);
When I do not set the canSortClientOnly property the order by is sent to my database resulting in an error, as the table does not contain that field, so I set the property. Now I get following error
Removing field from the sort Specifier array because it specifies canSort Client Only: true and all data is not yet client-side.
I also tried to use a sortNormilizer on the Name field which is my main sort criteria, but the normalizer is called before the selection value is set to the record.
record.setAttribute(CARealmDS.SELECTED,selected ? "a" : "b");
I also cannnot find a way to call the normalizer when selection changes.
Currently we are using Smart GWT Version 6.0p.
I don't think there is any standard function. Just use grid store update. Place checked items first.

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 append rows from xml

I'm using a grid which have editurl: "clientArray",datatype: 'xmlstring', datastr: '<%=_xml_string %>'.
I have a button in my page , and when i click it i make an ajax call and get an xml containing new rows that i want to add to my grid.
Currently i'm looping through the xml rows and using addRowData for each row.
My question is how can append these rows to the current grid? I want the rows that are currently in the grid to still be there and append to them the new rows from the xml i get.
Thank's In Advance.
You can for example prepare an array of data with the new rows. You can add all the rows in one call of addRowData (read the documentation for more information about different parameters of addRowData).
The things will be more easy if you would return JSON data from the server instead of XML. It is recommended for the most situations. Then you can just make one call of addRowData with the data returned from the server to append there to the grid. Optionally you can needed to use small customization of the localReader (see here for more information)
depending on the formatting of the returned data, you could use addXMLData, however you may have to manipulate the returned XML first in order to have it format correctly.

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