Author Topic: Swapping/Move the rows.  (Read 1755 times)

EPM Solutions

  • Pro Ultimate
  • Full Member
  • *
  • Posts: 182
    • View Profile
Swapping/Move the rows.
« on: September 27, 2017, 10:35:21 am »
Hi Team,

I have a grid with the field Serial, Name, Marks. The type of Serial field is option[drop down from 1 to 10]. Assume that i have 10 rows in the list and Serial field is from 1 to 10. So, if i click on rank 5 and select 1 here, i want to move it to number 1 and number 1 to 5. This is kind of swapping. Please suggest solution for this.
In another option, when i click on serial 5 and select 1, the current entire row should move to 1 and the 1st row should move to 2nd, and 2nd to 3rd..... till last row...  I want the hierarchy of serial is always from 1 to 10 in asc order. I have tried sort method, it works but it won't increment the old value. On changing from 5 to 1, current row is moved to 1st and 1st row to 2nd, but the Serial of old first row will be 1 only. I want to increment it to 1 and all other like this.

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6310
    • View Profile
Re: Swapping/Move the rows.
« Reply #1 on: September 27, 2017, 11:35:49 am »
I'm not sure whether I've followed the details of your post as the information is quite dense.

However swapping of rows could be done with js array splice method followed by refreshView().

Code: [Select]
    toolbar: {
      items: [{
        type: 'button',
        label: 'swap',
        listener: function() {
          debugger;
          var data = this.option('dataModel.data');
          var rd5 = data.splice(4, 1)[0]; //take out 5th row.
          var rd1 = data.splice(0, 1)[0]; //take out 1st row.
          data.splice(0, 0, rd5);
          data.splice(4, 0, rd1);
          this.refreshView();

        }
      }]
    }

http://jsfiddle.net/0jgmu7vq/