如何在 jQuery 数据表中显示'processing'?



我正在使用jquery datatables(angular datatables)与服务器端处理,消息"processing"在表上方。我可以通过 sDOM (lfrtip) 更改位置,但是是否可以将其放入数据表(将 p 放入 t)?

是的...有几种方法可以做到这一点。我喜欢使用"加载 gif"。所以,你的HTML看起来像这样:

<table  id="main_index">
<img id="loading_gif" src="images/ajax-loader.gif"> <!--this is your loading image or div-->
</table>

然后,您希望在表加载后隐藏此.gif。为此,您可以使用数据表回调函数。例如:

$("#main_compare").DataTable({
//all of your other datatables configuration followed by a comma then...
"drawCallback": function(settings, json) {
            $('#loading_gif').hide(); //hides the loading image once table is loaded
            //do anything else you want to have happen only once the table is loaded
                }
})

编辑

根据您的评论,我认为这就是您正在寻找的。

如果您希望消息在加载时显示在表的区域内,请使用以下结构:

<table  id="main_index">
    <div id="table_processing">Whatever text you want</div> 
    </table>

然后,您可以使用我的原始答案中的代码隐藏它,以便在表加载时隐藏此div。

  1. processing选项需要设置为 true和
  2. sDom选项中,需要字母r

    var options = {  
      "sDom": 'prtp',  
      "processing": true,  
      "serverSide": true,  
      "ajax": "/path/to/my/ajax.php"  
    }  
    var oTable = $('.datatables').dataTable(options);  
    

最新更新