jQuery EasyUI Forum
May 27, 2017, 12:58:55 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News:
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: [SOLVED] Moving data up and down on datagrid with scrollView  (Read 485 times)
Pierre
Sr. Member
****
Posts: 310


View Profile Email
« on: March 20, 2017, 04:47:22 AM »

Hello
I'm using datagrid scrollView need to move datagrid row up and down and here is sample code I found:

Code:
       function moveRow(step){
         var rows = $('#dg').datagrid('getRows');
         var row = $('#dg').datagrid('getSelected');
         if (row){
         var index = $('#dg').datagrid('getRowIndex',row);
         rows.splice(index,1);
     rows.splice(index+step,0,row);
         $('#dg').datagrid('loadData',rows);
         $('#dg').datagrid('scrollTo');
         }
        }

it works OK if my data are on single datagrid page but if there are more pages, it does not work correctly.
Any idea how to move datagrid rows up and down when using scrollView, please?
Thank you.
« Last Edit: March 21, 2017, 11:52:14 AM by Pierre » Logged
jarry
Administrator
Hero Member
*****
Posts: 1133


View Profile Email
« Reply #1 on: March 20, 2017, 08:14:46 AM »

Please call 'scrollTo' method to scroll to any row, no matter the row is in the current page or not.
Code:
$('#dg').datagrid('scrollTo', {
  index: index,
  callback: function(index){
    //...
  }
})
Logged
Pierre
Sr. Member
****
Posts: 310


View Profile Email
« Reply #2 on: March 20, 2017, 08:36:16 AM »

Hello Jarry
here are 10 records and it works fine:
http://code.reloado.com/oeasyrik1/90/edit#preview

and here are 150 records and if you go to second or third page and click on Move up or Down, it does not work (except on first page):
http://code.reloado.com/oeasyrik1/91/edit#preview

Thank you.
Logged
jarry
Administrator
Hero Member
*****
Posts: 1133


View Profile Email
« Reply #3 on: March 20, 2017, 05:20:26 PM »

Please look at this example http://code.reloado.com/oeasyrik1/92/edit#preview. It works fine.
http://code.reloado.com/oeasyrik1/92/edit#preview
Logged
Pierre
Sr. Member
****
Posts: 310


View Profile Email
« Reply #4 on: March 20, 2017, 11:18:11 PM »

Hello Jarry
thank you so much for your effort, now selection works but row is not moved Sad
How to move row up and down?
Thank you!
Logged
jarry
Administrator
Hero Member
*****
Posts: 1133


View Profile Email
« Reply #5 on: March 21, 2017, 09:01:45 AM »

The 'moveRow' function can be defined as:
Code:
function moveRow(step){
  var dg = $('#tt');
  var srcRow = dg.datagrid('getSelected');
  if (srcRow){
    var srcIndex = dg.datagrid('getRowIndex', srcRow);
    dg.datagrid('scrollTo', {
      index: srcIndex+step,
      callback: function(dstIndex){
        srcRow = $.extend(true,{},srcRow);
        var dstRow = $.extend(true,{},dg.datagrid('getRow', dstIndex));
        dg.datagrid('updateRow', {
          index: dstIndex,
          row: srcRow
        });
        dg.datagrid('updateRow', {
          index: srcIndex,
          row: dstRow
        });
        setTimeout(function(){
          dg.datagrid('selectRow', dstIndex);
        }, 0);
      }
    })
  }
}
Please look at this example http://code.reloado.com/oeasyrik1/93/edit#preview
Logged
Pierre
Sr. Member
****
Posts: 310


View Profile Email
« Reply #6 on: March 21, 2017, 11:51:53 AM »

Jarry you are the man!
Thank you so much for your help.
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!