khawarPK
khawarPK

Reputation: 2217

Display grid in reverse order from client side code

In short of time and limited access to production, i just want to display the result of my grid in reverse order, I mean currently it shown in Ascending order with respect of column 'Date', i want to display it descending order, sorting is not implemented on this grid and timely i have restriction to access server side code. Is it possible to manage this from client side.

Upvotes: 0

Views: 206

Answers (2)

Tariqulazam
Tariqulazam

Reputation: 4585

Possible... You may try the jQuery datatable plugin.

Fiddle - http://jsfiddle.net/tariqulazam/bEeHp

HTML

<table id="table">
    <tr>
        <td>A</td>    
    </tr>
    <tr>
        <td>B</td>    
    </tr>
    <tr>
        <td>C</td>    
    </tr>
    <tr>
        <td>D</td>    
    </tr>
</table>

<input type="button" value="Reverse" id="btnReverse"/>​

JavaScript

$("#btnReverse").click(function(){
   $("#table tr").each(function(i,li){
      $("#table").prepend(li)
   });
});​

Upvotes: 1

Bazzz
Bazzz

Reputation: 26922

You might be succesful using jQuery Tablesorter:

http://tablesorter.com/docs/

Disable the column headers click by applying headers { 0: { sorter: false}, 1: {sorter: false} } and use an initial sort direction on the column that would invert your whole dataset: sortList: [0,0].

You'll end up with something like this:

$(function() {
        $("#myTable").tablesorter({
            sortList: [0,0], 
            headers { 0:{sorter:false}, 1:{sorter:false}, 2:{sorter:false}} 
        }); 
    } 
);

Upvotes: 0

Related Questions