javascript - jquery 中的数据表

标签 javascript jquery datatables

我在一个项目中工作,我想在要显示的数据中添加网格类型工具。

为此,我使用了 jqueryDatatable 插件。

它运行良好且完美。

我唯一担心的是,每当我尝试从服务器(通过 Ajax)获取更新的表格时,数据表都会失去其功能。我的意思是每当我从服务器加载新表时,它都会以正常模式显示。

为此,我必须添加如下代码:

$.ajax({ 
    url: "<GIVE_ME_NEW_TABLE>",
    type: "POST",
    data: <THE_DATA_TO_BE_POSTED>,
    success: function(data){
        //data is fully prepared HTML string for representing the table
        $('#id_of_the_div_where_to_show_the_table').html(data);
        $('#id_of_the_table').dataTable({
           "bJQueryUI": true
        });
    },
    error : function(){
        //alert error
    }
});

所以这将在每次更新表的 Ajax 调用时调用。

最佳答案

或者,您可以通过 sAjaxSource 参数将 DataTables 连接到 ajax 数据源。您需要修改服务器端脚本以返回正确的响应。参见 ajax arraysajax objects DataTables 文档中的示例。

$(document).ready(function() {
    var oTable = $('#example').dataTable( {
        "bProcessing": true,
        "sAjaxSource": "/yoursite/ajaxTableDataSource",
    } );
} );

关于javascript - jquery 中的数据表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11389560/

相关文章:

javascript - 通过 Object.defineProperty 添加原型(prototype)属性覆盖构造函数属性

javascript - 在 React 组件中创建自定义函数

javascript - NodeJS 从现有的 tls.Server 创建 https

javascript - 在模块中查找函数

javascript - Logo 在为其兄弟动画后变得像素化

jquery - bxSlider 自定义上一个下一个按钮

jquery - 背景图像到背景颜色的过渡/动画

javascript - 数据表:确认用户希望分页

php - DataTables 导出 MySQL 表中的所有记录

javascript - 通过javascript向数据表添加行