Gajus
Gajus

Reputation: 73888

How to move a row to the top of the table?

var data = $('tbody');

console.log(data.filter(':first'), data.filter('tr.ay-sort-top'));

data.filter(':first').before(data.filter('tr.ay-sort-top'));

Console output from two runs:

[<tr class=​"ay-sort-top">​…​</tr>​] [<tr class=​"ay-sort-top">​…​</tr>​]
[<tr>​…​</tr>​] [<tr class=​"ay-sort-top">​…​</tr>​]

Upvotes: 0

Views: 2950

Answers (2)

Danil Speransky
Danil Speransky

Reputation: 30463

For example: $('tr:eq(2)').prependTo('table');​

See DEMO: http://jsfiddle.net/LxKSq/2/

Upvotes: 4

nnnnnn
nnnnnn

Reputation: 150070

If your question is actually "How do I move any rows with the "tr.ay-sort-top" class to the top of the table, leaving other rows in place?" then you can do something like this:

var $tbody = $("#yourTable tbody");
$tbody.prepend( $tbody.find("tr.ay-sort-top") );

Demo: http://jsfiddle.net/b89zY/1/

Upvotes: 0

Related Questions