Reordable rows on new table component

In this post, @bradlymathews showed a great idea on how to implement reordable rows on a table component, a much sought feature.

However, i tried implementing this code with the current table but it does not seem to work, since the table component was updated since then.

Can anyone help to refactor the code so that it will work?

This is my current version:

// js_SourceMovePrev
console.log(table2.selectedDataIndex);


if (table2.selectedRow.index > 0) {
	console.log('1');
  table2.selectRow({mode:'index', indexType: 'data', index: table2.selectedRow.index - 1});
}

// js_SourceMoveNext
if (table2.selectedRow.index < (table2.data.length - 1)) {
	console.log('2');table2.selectRow({mode:'index', indexType: 'data', index: table2.selectedRow.index + 1});
}

// js_SourceMoveFirst
if (table2.selectedRow.index > 0 ) {
  console.log('3');
	table2.selectRow({mode:'index', indexType: 'data', index: 0});
}

// js_SourceMoveLast
if (table2.selectedRow.index < table2.data.length - 1) {
	console.log('4');table2.selectRow({mode:'index', indexType: 'data', index: table2.data.length - 1});
}

Source post: Table with reordable rows - #4 by bradlymathews

@whynot,

I believe you have to replace any instance you have of table2.selectedRow.index
with table2.selectedDataIndex.

So the function for the PREVIOUS would be:

if (table1.selectedDataIndex > 0) {
	console.log('1');
  table1.selectRow({mode:'index', indexType: 'data', index: table1.selectedDataIndex- 1});
}

Hope this helps! :grinning:

Hey @whynot,
Just checking in to see whether this solved your issue.