EasyUI Forum
April 28, 2024, 01:19:23 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: Swap rows in grid  (Read 5432 times)
itay-g
Newbie
*
Posts: 35


View Profile
« on: August 03, 2014, 12:01:20 AM »

Hi,
I'm trying to swap rows in a grid. I'm doing it by using 'remove' method to remove the selected row and 'insert' method to insert the row into the new position. I noticed that when I'm doing that, the grid data doesn't update to the new order of the rows and that makes the swap look really odd because the rows move in a strange order(for example: suddenly one row goes to the bottom of the grid).
Is there a way to make the grid's data change?

Thank you very much  Smiley
Logged
stworthy
Administrator
Hero Member
*****
Posts: 3581


View Profile Email
« Reply #1 on: August 03, 2014, 12:47:29 AM »

No 'remove' method exists in the datagrid component, please use 'deleteRow' and 'insertRow' methods instead. It is easy to extend a new method to move a row in a datagrid component.
Code:
$.extend($.fn.datagrid.methods, {
moveRow:function(jq, param){
return jq.each(function(){
var dg = $(this);
var fromRow = dg.datagrid('getRows')[param.from];
var toRow = dg.datagrid('getRows')[param.to];
dg.datagrid('deleteRow', param.from);
var toIndex = dg.datagrid('getRowIndex', toRow);
dg.datagrid('insertRow', {
index: toIndex,
row: fromRow
});
})
}
})

The code below shows how to move a row #3 to the new position #5.
Code:
$('#dg').datagrid('moveRow', {
  from: 3,
  to: 5
});
Logged
itay-g
Newbie
*
Posts: 35


View Profile
« Reply #2 on: August 03, 2014, 01:51:28 AM »

Thank you.
When i wrote grid I meant to a treegrid, and with treegrid i can't work with indexes because the hierarchy.
Is there another way to make this work?

thanks
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!