2017-03-05 93 views
0

我在我的rails应用程序中使用jQuery数据表。我想将默认顺序添加到特定的列。我有它下面的jquery代码,数据表默认排序不工作

$(document).ready(function(){ 
     $('#sample-table-2').DataTable({ 
      responsive: true, 
      "pagingType": "simple", 
      bJqueryUI: true, 
      bServerSide: true, 
     "aaSorting": [[ 4, "asc" ]], // 
      sAjaxSource: $('#sample-table-2').data('source'), 
      "columnDefs": [ 
       { "width": "10%", "targets": column_count } 
       ] 
     }) 
     .on('order.dt', function() { eventFired('Order'); }) 
     .on('page', function() {setTimeout(function(){hideCellsOnMobile();},1000)}) 
     .on('search.dt', function() {setTimeout(function(){hideCellsOnMobile();},1000)}); 
     $("table#sample-table-2").parent().addClass("no-padding") 
}); 

但是这个默认顺序没有得到应用。

+0

目标预计根据文档的数组,所以你可能会想尝试'{“宽度”:“10%”,“目标”:COLUMN_COUNT]}' –

回答

0

你使用的是什么版本?你可以试试这个吗?

$(document).ready(function(){ 
     $('#sample-table-2').DataTable({ 
      responsive: true, 
      "pagingType": "simple", 
      bJqueryUI: true, 
      bServerSide: true, 
      order: [[ 4, "asc" ]], // 
      sAjaxSource: $('#sample-table-2').data('source'), 
      "columnDefs": [ 
       { "width": "10%", "targets": column_count } 
       ] 
     }) 
     .on('order.dt', function() { eventFired('Order'); }) 
     .on('page', function() {setTimeout(function(){hideCellsOnMobile();},1000)}) 
     .on('search.dt', function() {setTimeout(function(){hideCellsOnMobile();},1000)}); 
     $("table#sample-table-2").parent().addClass("no-padding") 
}); 
+0

能为您的需要这个答案的工作? – Jeremie