如何在Google Apps脚本中使用Datatables服务器端处理 [英] How to use Datatables server-side processing with Google Apps Script

查看:227
本文介绍了如何在Google Apps脚本中使用Datatables服务器端处理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在服务器端处理模式下使用数据表,数据以异步方式加载到批处理中。这对于海量数据集非常有用。该文档足够清晰( https://datatables.net/examples/data_sources/server_side.html ),但我正在努力研究如何在Google Apps脚本及其HTMLService中实现它。



我目前使用的是工作)是datatables 一次加载所有数据

  $(document).ready( function(){
google.script.run.withSuccessHandler(loadLogList).getLogList();
});

函数loadLogList(data){
if(data){
for(var i = 0; i< data.length; i ++){
htmlString + =< tr>< td> + data [i] [0] +< / td>;
htmlString + =< td> + data [i] [1] +< / td>;
htmlString + =< td> + data [i] [2] +< / td>;
htmlString + =< td> + data [i] [3] +< / td>< / tr>;
}
$(#LogListBody)。html(htmlString);

$ b $ var table = $(#LogList)。DataTable({
columnDefs:[
{orderData:[0],目标:[1]},
{
targets:[0],
visible:false,
searchable:false
}] ,
paging:true,
select:true
});

$ / code>

文档建议数据表需要如下初始化:

  $(document).ready(function(){
$('#example')。DataTable({
processing :true,
serverSide:true,
ajax:../server_side/scripts/server_processing.php
});
});

因此,我需要提供ajax和google.script.run。有任何想法吗?然后我需要在服务器端编写一个函数(Code.gs)来返回json格式的数据。如果有人有这样的示例代码,我也会非常感激。

谢谢

解决方案

查看文档ajax可以用几种不同的方式进行配置。一种是通过提供自定义功能。
https://datatables.net/reference/option/ajax



基于来自op的更多信息进行编辑。这是一个非常基本的设置:

  $('#example')。dataTable({
processing: true,
serverSide:true,
ajax:function(data,callback,settings){
google.script.run.withSuccessHandler(callback).getLogList(settings);
}
});


I'm trying to use datatables in server-side processing mode whereby data is loaded in batches, asynchronously. This is very useful for massive datasets. The documentation is clear enough (https://datatables.net/examples/data_sources/server_side.html), however, I'm struggling to work out how to implement it within Google Apps Script and its HTMLService.

What I'm currently using (which is working) is datatables loading all the data in at once:

$(document).ready(function() {
  google.script.run.withSuccessHandler(loadLogList).getLogList();
});

function loadLogList(data) {
  if (data) {
    for (var i = 0; i < data.length; i++) {
      htmlString += "<tr><td>" + data[i][0] + "</td>";
      htmlString += "<td>" + data[i][1] + "</td>";
      htmlString += "<td>" + data[i][2] + "</td>";
      htmlString += "<td>" + data[i][3] + "</td></tr>";
    }
    $("#LogListBody").html(htmlString);
  }

  var table = $("#LogList").DataTable( {
    "columnDefs": [
      { "orderData":[ 0 ],   "targets": [ 1 ] },
      {
      "targets": [ 0 ],
      "visible": false,
      "searchable": false
      } ],
    "paging": true,
    "select": true
  });
}

The documentation suggests that datatables needs initialising like this:

$(document).ready(function() {
    $('#example').DataTable( {
        "processing": true,
        "serverSide": true,
        "ajax": "../server_side/scripts/server_processing.php"
    } );
} );

So somehow I need to provide "ajax" with "google.script.run". Any ideas? I then need to write a function on the server-side (Code.gs) to return json-formatted data. If anyone has sample code for this also I'd be very grateful.

Thanks

解决方案

Looking at the docs ajax can be configured in a few different way. One is by providing a custom function. https://datatables.net/reference/option/ajax

Edit based on more info from op. This is the very basic setup:

$('#example').dataTable( {
  "processing": true,
  "serverSide": true, 
  "ajax": function (data, callback, settings) {
    google.script.run.withSuccessHandler(callback).getLogList(settings);
  }
} );

这篇关于如何在Google Apps脚本中使用Datatables服务器端处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆