JQuery数据表需要在底部总是显示空白记录(任何排序)

JQuery数据表需要在底部总是显示空白记录(任何排序),jquery,Jquery,我有一个混合的空,非空值表如果我点击列名排序将完成,我需要在底部空白记录总是如果我点击asc,desc排序什么我点击空白,空白记录需要显示在底部只有我想做的请帮助我任何一个 <html> <head> <link rel="stylesheet" type="text/css" href="http://cdn.datatables.net/1.10.2/css/jquery.dataTables.css"> <script src="http:/

我有一个混合的空,非空值表如果我点击列名排序将完成,我需要在底部空白记录总是如果我点击asc,desc排序什么我点击空白,空白记录需要显示在底部只有我想做的请帮助我任何一个

<html>
<head>
<link rel="stylesheet" type="text/css" href="http://cdn.datatables.net/1.10.2/css/jquery.dataTables.css">   
<script src="http://code.jquery.com/jquery-1.12.0.min.js"></script>
<script src="http://cdn.datatables.net/1.10.10/js/jquery.dataTables.min.js"></script>
<script>
    jQuery.extend(jQuery.fn.dataTableExt.oSort, {
    "non-empty-string-asc": function (str1, str2) {
        if(str1 == "")
           return 1;
        if(str2 == "")
           return -1;
           return ((str1 < str2) ? -1 : ((str1 > str2) ? 1 : 0));
    },                   
    "non-empty-string-desc": function (str1, str2) {
        if(str1 == "")
            return 1;
        if(str2 == "")
            return -1;
            return ((str1 < str2) ? 1 : ((str1 > str2) ? -1 : 0));
    }
    });
</script>
</head>
                <table id="example" class='dataTable fn dataTableExt oSort' border='1'>
                <thead>
                    <tr>
                        <th rowspan="2">Customer</th>
                        <th colspan="2">2016</th>
                        <th colspan="2">2015</th>
                    </tr>
                    <tr>
                        <th>Performance %</th> 
                        <th>Rank</th>
                        <th>Performance %</th> 
                        <th>Rank</th>
                    <tr>
                </thead>
                <tbody>
                    <tr>
                        <td>name1</td>
                        <td>100%</td>
                        <td>1</td>
                        <td>77%</td>
                        <td>2</td>
                    </tr>
                    <tr>
                        <td>name2</td>
                        <td></td>
                        <td>2</td>
                        <td>70%</td>
                        <td>5</td>
                    </tr>
                    <tr>
                        <td></td>
                        <td></td>
                        <td>2</td>
                        <td>72%</td>
                        <td>4</td>
                    </tr>
                    <tr>
                        <td></td>
                        <td></td>
                        <td></td>
                        <td></td>
                        <td></td>
                    </tr>
                    <tr>
                        <td>name5</td>
                        <td>98%</td>
                        <td>2</td>
                        <td>0</td>
                        <td></td>
                    </tr>
                    <tr>
                        <td>name6</td>
                        <td>99%</td>
                        <td></td>
                        <td></td>
                        <td></td>
                    </tr>
                    <tr>
                        <td>name7</td>
                        <td>71%</td>
                        <td></td>
                        <td>78%</td>
                        <td>1</td>
                    </tr>
                </tbody>
            </table>
            <script>
            var dataTable = $('#example').dataTable({
                "iDisplayLength": 8, //Number of rows
                "bLengthChange": false, //Disable "show 1-n entries"
                bFilter: false, //Disable filter
                bInfo: false,
                columnDefs: [{ "type" : "non-empty-string",targets: [0,4] }],
                "order": [[ 1, "desc" ],[ 2, "asc" ]]
            });
            </script>
</body>
</html>

extend(jQuery.fn.dataTableExt.oSort{
“非空字符串asc”:函数(str1、str2){
如果(str1==“”)
返回1;
如果(str2==“”)
返回-1;
返回((str1str2)?1:0));
},                   
“非空字符串描述”:函数(str1、str2){
如果(str1==“”)
返回1;
如果(str2==“”)
返回-1;
返回值((str1str2)?-1:0);
}
});
顾客
2016
2015
性能%
等级
性能%
等级
名称1
100%
1.
77%
2.
姓名2
2.
70%
5.
2.
72%
4.
名字5
98%
2.
0
名字6
99%
姓名7
71%
78%
1.
var dataTable=$(“#示例”).dataTable({
“iDisplayLength”:8,//行数
“bLengthChange”:false,//禁用“显示1-n个条目”
bFilter:false,//禁用筛选器
宾福:错,
columnDefs:[{“类型”:“非空字符串”,目标:[0,4]}],
“订单”:[[1,“说明”],[2,“asc”]]
});

您正在检查字符串是否为
==”

您确定空字符串不是null吗?我建议:

 jQuery.extend(jQuery.fn.dataTableExt.oSort, {
            "non-empty-string-asc": function(str1, str2) {
                if ( str1 == null || str1 == "")
                    return 1;
                if ( str2 == null || str2 == "")
                    return -1;
                return ((str1 < str2) ? -1 : ((str1 > str2) ? 1 : 0));
            },

            "non-empty-string-desc": function(str1, str2) {
                if ( str1 == null || str1 == "")
                    return 1;
                if ( str2 == null || str2 == "")
                    return -1;
                return ((str1 < str2) ? 1 : ((str1 > str2) ? -1 : 0));
            }
        });
为此:

            var dataTable = $('#example').dataTable({
                "iDisplayLength": 8, //Number of rows
                "bLengthChange": false, //Disable "show 1-n entries"
                bFilter: false, //Disable filter
                bInfo: false,
                columnDefs: [{ "type" : "non-empty-string",targets: [0,1,2,3,4] }],
                "order": [[ 1, "desc" ],[ 2, "asc" ]]
            });

这对我来说很有效,我不知道在哪里找到的,否则我会相信答案

     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 == " ") retVal = 1;
      else if (y == "" || y == " ") 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 == " ") retVal = -1;
      else if (y == "" || y == " ") retVal = 1;
      else if (x > y) retVal = 1;
      else retVal = -1; // <- this was missing in version 1

      return retVal;
  }
jQuery.fn.dataTableExt.oSort['mystring-asc']=函数(x,y){
var-retVal;
x=$.trim(x);
y=$.trim(y);
如果(x==y)retVal=0;
如果(x==“”| x==“”)retVal=1;
如果(y==”| y==”)retVal=-1;
如果(x>y)retVal=1,则为else;
else-retVal=-1;//y)retVal=1;

else-retVal=-1;//这对我也没有帮助。好吧,请给我们提供更多详细信息。到底发生了什么?升序、降序排序只起作用,我需要空记录只保留在底部进行任何排序。如果按名称或排名排序,则顺序工作得很好。是否希望它在所有列中都起作用?我已将答案编辑为include感谢您的帮助现在空记录位于表的底部这没问题,但是如果我单击“为空和值排列其工作正常”,则性能值的顺序不正确。但是性能列为空位于表的底部,值的顺序不正确如何根据值变为正确的顺序。
            var dataTable = $('#example').dataTable({
                "iDisplayLength": 8, //Number of rows
                "bLengthChange": false, //Disable "show 1-n entries"
                bFilter: false, //Disable filter
                bInfo: false,
                columnDefs: [{ "type" : "non-empty-string",targets: [0,1,2,3,4] }],
                "order": [[ 1, "desc" ],[ 2, "asc" ]]
            });
     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 == " ") retVal = 1;
      else if (y == "" || y == " ") 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 == " ") retVal = -1;
      else if (y == "" || y == " ") retVal = 1;
      else if (x > y) retVal = 1;
      else retVal = -1; // <- this was missing in version 1

      return retVal;
  }