Different definitions of column index of dataTable.NET

dataTable.NET is a jQuery plug in a third party library, used to implement the table in the web page interaction controls, with the recent addition there Telerik UI of RadGrid (action required postback).

Setting dataTable.NET by simple, so that the sequence has a good define table columns adjust the displayed or hidden, sort can also be single or multiple columns.

In the course have come across some interesting situation.

<table id="test-listing">
  <thead>
    <tr>
      <th>column0</th>
      <th>column1</th>
      <th>column2</th>
      <th>column3</th>
      <th>column4</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>...</td>
      ...
    </tr>
    ...
  </tbody>
</table>

In the above table, for example, when it is necessary to reorder the columns in the display, and when the hide certain columns

$('#test-listing').DataTable({
    paging: false,
    ordering: true,
    fixedHeader: true,
    columnDefs: [3,1,4,2,0],
    colReorder: {
        order: [{"visible":false, "target":2}],
        enable: false
    },
    "search": {
        "search": "xxxx"
    },
    order: [[4, "asc"]],
    "dom":
          "<'row'f>" +
          "<'row dt-table'" +
          "<'sixteen wide column'tr>" +
          ">" +
          "<'row'i>"
});

The above setting, the results displayed on the page

column3 column1 column4 column0
       

Column4 arranged in ascending order. Index used in setting the initial column of the index is defined in the page.

 When the load table has ended, the following method may be used to obtain the current sort:

var table = $('#test-listing').dataTable();
var currentSort = table.fnSettings().aaSorting;

The resulting sort colums of the index will be based on the currently displayed prevail, [[2, "asc"]]

If you need to catch to keep the current sort cookie, as the setting for the next time the page is displayed, then remember to do first conversion process.

Guess you like

Origin www.cnblogs.com/sipher/p/11235499.html