用于jQuery更改数据集的DataTables插件?

时间:2014-11-02 10:50:45

标签: javascript jquery datatables jquery-datatables

我得到了一个用这样的空数据集初始化的JQuery DataTable:

oTable = $('#accountsDefaultList').DataTable({
           "bStateSave": true,
           "aaData": accountsDefaultList(),
           "aoColumns": [
              {
                   "mData": "id",
                   "mRender": function (data) {
                       return '<button class="edit"><i class="fa fa-pencil-square-o"></i></button><button class="delete"><i class="fa fa-trash-o"></i></button>';
                   }
               },
               { "mData": "title" }
          ],
           "sDom": "<'dt-toolbar'<'col-xs-12 col-sm-6 hidden-xs'f><'col-sm-6 col-xs-12 hidden-xs'T<'toolbar'C>>r>" +
                   "Rt" +
                   "<'dt-toolbar-footer'<'col-sm-6 col-xs-12 hidden-xs'i><'col-xs-12 col-sm-6'p>>",
           "autoWidth": false,
           "oTableTools": {
               "aButtons": [
               "copy",
               "xls",
                  {
                      "sExtends": "print",
                      "sMessage": "Generated by Procoor <i>(press Esc to close)</i>"
                  }
               ],
               "sSwfPath": "javaScript/smartAdmin/plugin/datatables/swf/copy_csv_xls_pdf.swf"
           },
           "fnStateSave": function (oSettings, oData) {
               localStorage.setItem('accountsDefaultList', JSON.stringify(oData));
           },
           "fnStateLoad": function (oSettings) {
               return JSON.parse(localStorage.getItem('accountsDefaultList'));
           },
           "sPaginationType": "full_numbers",
           "preDrawCallback": function () {
               // Initialize the responsive datatables helper once.
               if (!responsiveHelperaccountsDefaultList) {
                   responsiveHelperaccountsDefaultList = new ResponsiveDatatablesHelper($('#accountsDefaultList'), breakpointDefinition);
               }
           },
           "rowCallback": function (nRow) {
               responsiveHelperaccountsDefaultList.createExpandIcon(nRow);
           },
           "drawCallback": function (oSettings) {
               responsiveHelperaccountsDefaultList.respond();
           }
});

我用它来用新数据更新数据集,但它似乎根本不起作用

accountsDefaultList.subscribe(function () {
     var data = accountsDefaultList();
     oTable.data(data);
});

我测试了数据是否被返回并且除了数据集更新之外每件事情都很好,我看到了使用fnClearTable和fnAddData之类的建议,但这些建议甚至不存在于datatables api中。

0 个答案:

没有答案