Refresh a Grid, keeping filtering and sorting the same

Hi there,

I have a grid that is backed by a dhtmlxconnector. When someone edits a cell, I want to update all cells that match some criteria to match. I have written the code in the beforeUpdate event on the server side connector, and I just want to refresh the grid to read the new values (but I want it to remember the filtering, sorting etc).

In a simplified example below (there are lots more columns), if I change the driver for one journey, then I want it to be updated for all journeys for that duty. So - if I change the driver for journey 1 to be “Mr C”, then I want journey’s 2 and 3 to also be updated to have the driver “Mr C”.

journey     duty     driver
1            d1       Mr A
2            d1       Mr A
3            d1       Mr A
4            d2       Mr B
5            d2       Mr B
6            d2       Mr B

The code on the server is fairly straightforward - update the table setting driver to the value for the driver field on the updated row, where the duty id is the same. Having done that, I want to refresh the dhtmlxgrid on the client side to reflect this change. I thought something like the following should work, but it doesn’t.

	dp.attachEvent("onAfterUpdateFinish", function() {
		alert("Database is updated correctly, but need to make a call here that will reload the grid, preserving the current filters+sorting.");
		return true;

A workaround that I can think of is to implement the same changes to the front end in javascript, but this feels like a dirty hack, and it seems to be that there should be a simple function “reloadGrid()” that reloads the data from the connector, preserving the current filtering and sorting.

Does anyone have any ideas?


In this case you may try to use updateFromXML() method.
Here is the tutorial: … atefromxml

Thanks for that. I have used updateFromXML() method, but it doesn’t do what I need it to.

It works fine when there are no filters set in the grid. However, it fails when there are filters set.

Does this mean that I need to loop through the columns and read the current values of the filters and the sort and include those in the string for the updateFromXML() method? Will that work?

Something like:

	return mygrid.getFilterElement(colIndex).value;

dp.attachEvent("onAfterUpdateFinish", function() {

So - it appears that updateFromXML() method just isn’t clever enough to handle the updates, even when the sort state and filter values are appended to the query string. However, since I had pulled all the variables out anyway, it was a quick change to clearAndLoad().

For those who run into the same issue as me, try the following snippet. Note that my default sorting column is column 3 … you may want to change yours to 0.

	dp.attachEvent("onAfterUpdateFinish", function() {

		var defaultCol=3;
		var defaultOrder="asc";
		var state=mygrid.getSortingState();
		var column = (state.length<1?defaultCol:state[0]);
		var order = (state.length<1?defaultOrder:state[1]);

		var filters = "";
		for(var i=0;i<mygrid.getColumnsNum();i++){