EasyUI Forum

General Category => EasyUI for jQuery => Topic started by: Wojak on October 05, 2023, 03:28:17 PM



Title: [SOLVED] Swap rows in datagrid
Post by: Wojak on October 05, 2023, 03:28:17 PM
Hi,
I would like to add a button that allows the rows to be swapped up and down. I found a post from 2014, but it doesn't work :(

https://www.jeasyui.com/forum/index.php?topic=3634.0 (https://www.jeasyui.com/forum/index.php?topic=3634.0)

Snippet of the code
Code:
function dgSwapColumns(from, to) {
      $('#dg).datagrid('moveRow', { from: from, to: to });
}

It gives me this error
Code:
Uncaught TypeError: $.fn.datagrid.methods[_8ee] is not a function
    at $.fn.datagrid (<anonymous>:12356:35)
    at dgSwapColumns ((index):89:30)
    at HTMLAnchorElement.onclick ((index):1:1)


Title: Re: Swap rows in datagrid
Post by: jarry on October 14, 2023, 06:14:00 PM
This code shows how to swap two rows in a datagrid.
Code:
var index1 = 2;
var index2 = 3;
var dg = $('#dg');
var rows = dg.datagrid('getRows');
var temp = rows[index1];
rows[index1] = rows[index2];
rows[index2] = temp;
dg.datagrid('refreshRow',index1);
dg.datagrid('refreshRow',index2);


Title: [SOLVED] Swap rows in datagrid
Post by: Wojak on October 16, 2023, 09:13:30 AM
Thanks for advice  ;)

Works like a glove