2

在我的表(JQuery 数据表)中,有一行(最后一行)必须始终位于末尾(用于总计)。

我可以区分它的值,因为它们就像:

<td><span class="last-row">MY VALUE</span></td>

如何使排序功能始终将这种行放在末尾,无论按哪一列排序,也不管排序是 ASC 还是 DESC?

4

2 回答 2

3

只是为了充实 SiGanteng 的建议,您可以使用该元素tfoot在表格中定义页脚行。

<table>
    <thead>
      <tr> 
      <!-- modern browsers know how to render these, it is also used by screen readers and other assistive technologies -->
        <td>header 1</td>
        <td>header 2</td>
        <td>header 3</td>
      </tr>
    </thead>
    <tfoot> <!--ditto-->
      <tr>
        <td colspan="3">footer text</td>
      </tr>
    </tfoot>
    <tbody>
      <!-- regular html rows & cols here -->
    </tbody>
</table>
于 2013-03-27T03:12:25.700 回答
0

Yes

If it must be a td element then you will have to create a custom function sorting plugin http://www.datatables.net/plug-ins/sorting

Heres an example of a sort plugin that always puts null fields at the bottom, you can adjust to look for your special value in the column with whatever type of sort it is by subbing out nbsp; for your val, and assign this in aoColums stype

jQuery.fn.dataTableExt.oSort['mystring-asc'] = function(x,y) {
var retVal;
x = $.trim(x);
y = $.trim(y);

if (x==y) retVal= 0;
else if (x == "" || x == "&nbsp;") retVal=  1;
else if (y == "" || y == "&nbsp;") retVal=  -1;
else if (x > y) retVal=  1;
else retVal = -1;  // <- this was missing in version 1

return retVal;
 }
jQuery.fn.dataTableExt.oSort['mystring-desc'] = function(y,x) {
var retVal;
x = $.trim(x);
y = $.trim(y);

if (x==y) retVal= 0; 
else if (x == "" || x == "&nbsp;") retVal=  -1;
else if (y == "" || y == "&nbsp;") retVal=  1;
else if (x > y) retVal=  1;
else retVal = -1; // <- this was missing in version 1

return retVal;

 }

The assignment in datatable() function

 ...
 "aoColumns": [
  { "sType": 'mystring' },
 ...
于 2013-03-27T03:03:04.337 回答