On initial load of my datatable via ajax, the table shows no data and 'Loading...' appears in the table body.
在通过ajax初始加载我的数据表时,该表显示没有数据,表正文中出现“正在加载...”。
On DataTable().ajax.reload(), the 'Loading...' text is not present.
在DataTable()。ajax.reload()上,“Loading ...”文本不存在。
I know I can turn on the processing option to get the bar across the table, but if I do this then on initial loading my users see both 'Loading...' in the table body and 'Processing...' on top of that.
我知道我可以打开处理选项以获得表格中的条形图,但是如果我这样做,那么在初始加载时我的用户会看到表格正文中的“正在加载...”和“处理...”之上那。
Has anyone found a solution to have one all the time or the other? I would prefer to replace the table body with 'Loading...' for each ajax reload.
有没有人找到一个解决方案,一直有一个或另一个?我更愿意为每个ajax重新加载用'Loading ...'替换表体。
Thanks!
2 个解决方案
#1
5
With Datatables 1.10 I had the same issue. I found a way to get this to work. If you use the preXhr event which fires before the ajax call you can
使用Datatables 1.10,我遇到了同样的问题。我找到了一种让它发挥作用的方法。如果你使用在ajax调用之前触发的preXhr事件,你可以
- clear the table
- Set the draw count back to 0, which triggers the initial message again
-
ReDraw the table and loading will appear.
重新绘制表格并显示加载。
mydataTable.on('preXhr.dt', function(e, settings, data){ $(this).dataTable().api().clear(); settings.iDraw = 0; //set to 0, which means "initial draw" which with a clear table will show "loading..." again. $(this).dataTable().api().draw(); });
清桌子
将绘制计数设置回0,这将再次触发初始消息
#2
-1
There are "language" options where you can dictate what shows up during various events. DataTables has great documentation showing it. https://datatables.net/reference/option/language.processing
有“语言”选项,您可以在其中指定各种事件中出现的内容。 DataTables有很好的文档显示它。 https://datatables.net/reference/option/language.processing
#1
5
With Datatables 1.10 I had the same issue. I found a way to get this to work. If you use the preXhr event which fires before the ajax call you can
使用Datatables 1.10,我遇到了同样的问题。我找到了一种让它发挥作用的方法。如果你使用在ajax调用之前触发的preXhr事件,你可以
- clear the table
- Set the draw count back to 0, which triggers the initial message again
-
ReDraw the table and loading will appear.
重新绘制表格并显示加载。
mydataTable.on('preXhr.dt', function(e, settings, data){ $(this).dataTable().api().clear(); settings.iDraw = 0; //set to 0, which means "initial draw" which with a clear table will show "loading..." again. $(this).dataTable().api().draw(); });
清桌子
将绘制计数设置回0,这将再次触发初始消息
#2
-1
There are "language" options where you can dictate what shows up during various events. DataTables has great documentation showing it. https://datatables.net/reference/option/language.processing
有“语言”选项,您可以在其中指定各种事件中出现的内容。 DataTables有很好的文档显示它。 https://datatables.net/reference/option/language.processing