jqgrid - update multiples rows with "custom" form like advance search - jqgrid

I need to filter (or not) records in a jqgrid and be able to update all the filtered records by changing the value (s) in one or more columns.
The solution that I thought was to have a form dialog similar to that of the advanced search where the user can select which columns he wants to update and with what values.
In this way I could call a javascript method that sends to the server the filter selected by the user + the array of columns and values ​​selected by the user.
Any recommendation?
edit: version 5.3.1

I can recommend you to build your own form similar to the search one and set which field with what value to be updated. Clicking on a submit you will send the filter and the data fields with values which should be updated.

Related

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.

Best practices for adding/editing UI table data while filtering

Does any one know If there are any best-practices for editing/adding data in UI table while its data is filtered?
Example 1:
Suppose we have a table with two options: add new record and edit selected one. Moreover, the table has an option to filter data over column A.
Now, if the table is filtered by filtering column A with value '1' and I want to add a new record with value in column A that matches filter requirements, what should happen:
The table should refresh and display filtered records with selected newly added record.
The table should reset filter and show all records witch new one selected.
The table should do nothing and display filtered records as they were. Newly added record will be displayed when the filter resets.
For me intuitively the best solution is number 1. But then how to solve the problem in example number 2:
Example 2:
If the table is filtered by filtering column A with value '1' and I want to add a new record that in column A has value '2' what should happen:
The table should display filtered records with selected newly added record despite it does not matche the filter.
The table should reset the filter, and all records should be displayed with new one selected.
The table should do nothing and display filtered records as they were.
The same story is when we have filtered records, and in selected record we want to edit value upon which the filtering took place. Does the edited record should than disapear or filtre should be reset?
Or maybe the best way is to disable add/edit operations while filter is on?
I don't know if there is any best practices about it but I have also encountered the problem before. Two different solutions as I came up with:
Edited/Inserted record should not be filtered until the next time a filter is applied or filter is reset. The record should also be shown different (i.e. darker background color, or an icon, or tooltip) than others implying it was edited and is not being filtered.
The record should be left in focus after being edited or inserted. As soon as it loses focus, filter should be applied to it. The ideal solution is if the record is filtered out, it shouldn't immediately go out of vision. For instance it may go invisible with an animation.
I just checked the google docs and libre office, both of them just display the new record regardless of the filter. You need to re-apply the filter to hide them from view (in both cases the column "A" is filtered by "value 1"):

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.

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?

YUI DataTable - multiple columns filtering

I know, that it is possible to filter dataTable Control on client as it is shown in this exaple:
http://developer.yahoo.com/yui/examples/datatable/dt_localfilter.html
Is it also possible to filter more columns? I'd like to have 2 textfields, and when I type sth to the first one, DataTable would filter according to the 'areacode' (from the example) and when I type sth to the second one, DataTable would filter according to the 'state'.
Is this possible somehow? Thanks for any help.
The simplest way to modify the existing example would be to build a request string that contains the information for each text box. For example (column1=a&colum2=b), modify the doBeforeCallback to split the request and do the filtering for each column.

Resources