如何从jquery更新datatable对象

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了如何从jquery更新datatable对象相关的知识,希望对你有一定的参考价值。

我想通过在特定索引上添加key => value对来更新datatable对象,例如 - 下面是我的datatable对象值。所以我只想在jquery的列[0] ['search']索引下添加一个键值对。我试过这个dataTable.columns(0).search({“Key”:“value”})。draw();但它不起作用.-

Array
(
    [draw] => 2
    [columns] => Array
        (
            [0] => Array
                (
                    [data] => 0
                    [name] => 
                    [searchable] => true
                    [orderable] => true
                    [search] => Array
                        (
                            [value] => 
                            [regex] => false
                        )

            )

        [1] => Array
            (
                [data] => 1
                [name] => 
                [searchable] => true
                [orderable] => true
                [search] => Array
                    (
                        [value] => 
                        [regex] => false
                    )

            )

        [2] => Array
            (
                [data] => 2
                [name] => 
                [searchable] => true
                [orderable] => true
                [search] => Array
                    (
                        [value] => 
                        [regex] => false
                    )

            )

        [3] => Array
            (
                [data] => 3
                [name] => 
                [searchable] => true
                [orderable] => true
                [search] => Array
                    (
                        [value] => 
                        [regex] => false
                    )

            )

        [4] => Array
            (
                [data] => 4
                [name] => 
                [searchable] => true
                [orderable] => true
                [search] => Array
                    (
                        [value] => 
                        [regex] => false
                    )

            )

        [5] => Array
            (
                [data] => 5
                [name] => 
                [searchable] => true
                [orderable] => true
                [search] => Array
                    (
                        [value] => [object Object]
                        [regex] => false
                    )

            )

        [6] => Array
            (
                [data] => 6
                [name] => 
                [searchable] => true
                [orderable] => true
                [search] => Array
                    (
                        [value] => 
                        [regex] => false
                    )

            )

        [7] => Array
            (
                [data] => 7
                [name] => 
                [searchable] => true
                [orderable] => true
                [search] => Array
                    (
                        [value] => 
                        [regex] => false
                    )

            )

        [8] => Array
            (
                [data] => 8
                [name] => 
                [searchable] => true
                [orderable] => true
                [search] => Array
                    (
                        [value] => 
                        [regex] => false
                    )

            )

        [9] => Array
            (
                [data] => 9
                [name] => 
                [searchable] => true
                [orderable] => true
                [search] => Array
                    (
                        [value] => 
                        [regex] => false
                    )

            )

    )

[order] => Array
    (
        [0] => Array
            (
                [column] => 0
                [dir] => desc
            )

    )

[start] => 0
[length] => 10
[search] => Array
    (
        [value] => 
        [regex] => false
    )

[type] => mytask

)

答案

如果要向服务器提交其他键/值对,请使用ajax.data选项。

例如:

$('#example').dataTable( {
  "ajax": {
    "url": "data.json",
    "data": function ( d ) {
        d.extra_search = $('#extra').val();
    }
  }
} );

以上是关于如何从jquery更新datatable对象的主要内容,如果未能解决你的问题,请参考以下文章

使用 jquery.dataTables 从 observableArray 中删除项目后 UI 不更新

如何使用 SQL 命令从我的 DataTable 对象中使用 foreach-loop 更新 C# 中的 MS Access 数据库?

单击按钮时,如何触发 jquery datatables fnServerData 通过 AJAX 更新表?

如何从 jQuery dataTables 中获取分页信息

如何从 jQuery Datatable 中获取过滤后的数据结果集

如何动态更改 jQuery Datatables 高度