如何限制jQuery数据表中的初始API调用

时间:2019-02-18 05:40:09

标签: jquery datatables

我正在使用jquery.dataTables.js来显示我的表数据,但是在初始加载时,我想要一个空表,并且当我选择了一些过滤器之后,相应地表会加载数据。我也使用iDeferLoading,但是它需要加载一些初始数据,但是我想要一个空表

版本1.9.4

文件jquery.dataTables.js

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.js")></script>
    <script type="text/javascript" src="https://cdn.datatables.net/1.9.4/js/jquery.dataTables.js")></script>
</head>
<body>
    <script type="text/javascript">
        (function () {
    $.extend(true, window, {
        Admin: {
            LogEntryTable: LogEntryTable
        }
    });
    function LogEntryTable(options) {
        var table = $(options.tableId).dataTable({
            bServerSide: true,
            bSort: false,
            bAutoWidth: false,
            iDisplayLength: 100,
            bScrollInfinite: false,
            bScrollCollapse: true,
            sScrollY: "550px",
            sDom: "rtip",
            sAjaxSource: options.url,
            sAjaxDataProp: "model",
        });
    }
})();
        </script>
        <script type="text/javascript">
            $(document).ready(function () {
                var table = new Admin.LogEntryTable(
                    {
                        tableId: "#jLogEntryTable",
                        url: 'http://localhost/abcd'
                    });
            });
        </script> 
    <div>
        <span>Log Entries</span>
    </div>
    <table class="mws-table" id="jLogEntryTable">
        <thead>
            <tr>
                <th>Date (UTC)</th>
                <th></th>
                <th>App</th>
                <th>Machine</th>
                <th>Logger</th>
                <th>Message</th>
                <th>Exception</th>
            </tr>
        </thead>
        <tbody>         
            <tr>
                <td colspan="7" class="dataTables_empty">Loading data from server</td>
            </tr>
        </tbody>
    </table>
    <div>
    <button>Search</button
    </div>
</body>
</html>

1 个答案:

答案 0 :(得分:0)

初始化DataTable,第一次加载时不带任何选项 选择过滤器后,使用

销毁旧的数据表
$ git next-commit "Implement client-side validation"
ok
$ git commit -m from-next-commit
ok
# git commit -m from-next-commit
error : already used
$ git next-commit "Optimize get_request"
ok
$ git commit -m from-next-commit
ok

,然后使用原始选项重新初始化数据表

编辑 JS小提琴 http://jsfiddle.net/tfyjmb4n/