【问题标题】:Hide DataTable while loading加载时隐藏数据表
【发布时间】:2016-08-16 16:59:21
【问题描述】:

我正在使用 jquery DataTable v 1.10.11 .. 我想隐藏整个表和显示它的 div,同时数据表通过 ajax 调用从服务器加载数据.. 我搜索但找到了初始化建议ajax 调用成功的表我不能做,因为我在同一个表上执行许多任务,如添加/编辑/删除。下面是我的 dataTable 声明。

$(document).ready(function (){
//some code ....

var listTable = $('#listTable').DataTable({
                'fnCreatedRow': function (nRow, aData, iDataIndex) {
                $(nRow).attr('id', 'my' + iDataIndex);
                $(nRow).attr('name', 'my' + iDataIndex); // or whatever you choose to set as the id
                },
                "tableTools": {
                        "sSwfPath": "http://cdn.datatables.net/tabletools/2.2.2/swf/copy_csv_xls_pdf.swf",
                        "aButtons": [
                            {
                                "sExtends": "copy",
                                "sButtonText": "Copy To ClipBoard",
                            },
                            {
                                "sExtends": "xls",
                                "sFileName": "*.xls",
                                "sButtonText": "Download XLS",
                            },
                            {
                                "sExtends": "print",
                            }                          
                     ]
                  },
                  "bInfo": false,
                  "sEmptyTable": "There are no records",
                  "processing": true,
                  "oLanguage": {
                        "sProcessing": "<img src='${request.contextPath}/images/ajax-loader.gif'>"
                },
                "dom": '<"toolbar">T<"clear">lfrtip',
                "order": [[ 1, "desc" ]]
    });

    $('.dataTables_empty').html("");

//some more code 
//some url
listTable.ajax.url(url).load()

    });

下面是表格HTML代码

<div id="data_table_travelHistory" style="margin:0 auto; padding-top:10px; width:90%;">
              <table cellpadding="0" cellspacing="0" border="0"  id="listTable" style="width:100%;" class="table table-striped table-bordered">
              <thead class="alignCenter">
                 <tr>
          <th class="headerclass">Start Date</th>
          <th class="headerclass">Approval Status</th>
          <th class="headerclass">Created On</th>
          <th class="headerclass">Action</th>
                </tr>
              </thead>
              <tbody></tbody>
              <tfoot  class="alignCenter headerclass">
                 <tr>
          <th class="headerclass">Start Date</th>
          <th class="headerclass">Approval Status</th>
          <th class="headerclass">Created On</th>
          <th class="headerclass">Action</th>
                 </tr>
              </tfoot>
              </table>
           </div>

目前我可以在加载 DataTable 时显示 gif 加载图像。但是初始化的表总是出现在后台,看起来不太好。有没有办法我可以隐藏整个 DataTable 和它所在的 div 并且只显示加载栏....任何帮助将不胜感激...

【问题讨论】:

    标签: javascript jquery html ajax datatable


    【解决方案1】:

    您可以在就绪事件中初始化表格,然后在 ajax 请求结束时添加删除显示/隐藏表格的 css 类。

    【讨论】:

    • gif 可以在同一个容器中,您可以使用相同的方法来显示/隐藏 gif。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-08-21
    • 1970-01-01
    • 2020-02-05
    • 1970-01-01
    相关资源
    最近更新 更多