Mike Miller wrote:
Thanks for this...it truly is amazing what jquery can do. A quick
question for you though regarding the index property. If I want to
make this more dynamic...do you know how I would find out the value of
the rowIndex property for the table row I want to move?
Get it directly from the tr element:
var rowIndex = $('tr')[0].rowIndex;
That's shorter than using all jQuery:
var rowIndex = $('tr').attr('rowIndex');
The plugin could of course be changed to take tr elements instead of
passing indices and you don't need to handle the rowIndex:
jQuery.fn.moveRow = function(from, to, useBefore) {
var trs = this.find(">tr");
$(from)['insert' + (useBefore && 'Before' || 'After')](to);
return this;
};
Usage:
var from = $('tr:eq(3)'); // 4th row
var to = $('tr:eq(0)'); // 1st row
$('tbody').moveRow(from, to); // insert 4th row after 1st row
Is that what you need?
--Klaus