EasyUI Forum
June 15, 2024, 05:15:37 PM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News:
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: TreeGrid - How to Define sorted column+order on loading  (Read 17134 times)
amir-t
Newbie
*
Posts: 48


View Profile
« on: June 17, 2014, 08:42:51 AM »

Hi,

i'm using Tree-grid in chrome browser, with the dynamic loading and server sorting (using the 'loader' callback).
In our page, we're using a dynamic panel which can switch between views of treeGrids.
Our problem is - in case someone sorted a specific treeGrid component (in a specific view), by a certain column,
when we'll switch back to this treeGrid view and load its data (which will be sorted on server side) we need to define and indicate that this initialized treeGrid is sorted, in similar to when someone pressing a sortable column (with the suitable asc\desc sort icon)  as in the following image:
.

In addition, after the treegrid has been loaded with its suitable sorting definition (for each treeGrid view, we keep a state which contains the sorting order and column data), we want to make sure that the treeGrid is set to the assigned sorting order+column.
So if someone will press on the sorting column header (to toggle the sort order),
the sorting order will be toggled correctly:


How can we implement the above requirement?

Thanks in advance.
Logged
stworthy
Administrator
Hero Member
*****
Posts: 3581


View Profile Email
« Reply #1 on: June 18, 2014, 12:07:02 AM »

You can specify the 'sortName' and 'sortOrder' properties when creating the treegrid, or call 'sort' method to sort the treegrid at runtime. When calling 'sort' method, you can specify the 'sortName' and 'sortOrder' properties.
Code:
$('#tg').treegrid('sort', {			// sort on a column with specified order
sortName: 'productid',
sortOrder: 'desc'
});
Logged
amir-t
Newbie
*
Posts: 48


View Profile
« Reply #2 on: June 18, 2014, 12:37:31 AM »

Hi,
The 'sort' method is not a suitable solution in our case, since if we'll call the 'sort' method, after the TreeGrid has been created and loaded with data, the treeGrid will send a server request in order to sort its data, but, in our scenario, the treeGrid is already created and loaded with SORTED data , so we don't want to make another server sort call where our sorted data is already fetched at the first loader call. What we need is only to set in the treeGrid its current sorted column + order state and indication (as seen in the attached image before), without actually making a server Sort call.
Logged
stworthy
Administrator
Hero Member
*****
Posts: 3581


View Profile Email
« Reply #3 on: June 18, 2014, 01:16:53 AM »

The 'sort' method is the simple way to change the sorting status except that it will send the request to server. But you can use the 'onBeforeLoad' event to determine if this request can be sent to server.
Code:
$('#tg').treegrid({
  onBeforeLoad:function(){
    return false; // return false in some condition to prevent from sending request to server
  }
});
If the 'onBeforeLoad' return false, calling 'sort' method only changes the sorting status without sending request to server.
Logged
amir-t
Newbie
*
Posts: 48


View Profile
« Reply #4 on: June 18, 2014, 05:23:45 AM »

Thanks, we'll do that.

By the way, is there an alternative method or logics to 'sort' method in version 1.3.5?
In our development we're working on 1.3.5 for now.
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines Valid XHTML 1.0! Valid CSS!