One Datatables.net table with multiple ajax calls from Sharepoint 2010 REST API

前端 未结 1 1950
执笔经年
执笔经年 2021-01-15 18:02

I am new here, so exuse me in advance for the lengthy question. I\'m new to SP2010, and so far followed the following tutorial to make JQuery Ajax call to my SP List: Who Ne

相关标签:
1条回答
  • 2021-01-15 19:01

    If you cannot avoid the limitation of 1000 records per Ajax call, you can use the code below.

    It uses $.when to execute callback when both Ajax calls were successful.

    function LoadData()
    {
       var call1 = $.ajax({
          url: "https://SP2010_siteaddress.com/site/_vti_bin/listdata.svc/Listname?$select=Data1,Data2,Data3,Data4,Data5",
          type: "GET",
          dataType: "json",
          headers: {
             Accept: "application/json;odata=verbose"
          }       
       });
    
       var call2 = $.ajax({
          url: "https://SP2010_siteaddress.com/site/_vti_bin/listdata.svc/Listname?$select=Data1,Data2,Data3,Data4,Data5&$skiptoken=2000",
          type: "GET",
          dataType: "json",
          headers: {
             Accept: "application/json;odata=verbose"
          }       
       });
    
       // When both Ajax requests were successful
       $.when(call1, call2).done(function(a1, a2){
          // a1 and a2 are arguments resolved for the call1 and call2 ajax requests, respectively.
          // Each argument is an array with the following structure: [ data, statusText, jqXHR ]
    
          // Merge data from two Ajax calls
          var data = a1[0].d.results.concat(a2[0].d.results);
    
          $('#example').dataTable({
             "aaData": data,
             "aoColumns": [
                { "mData": "Data1" },
                { "mData": "Data2" },
                { "mData": "Data3" },
                { "mData": "Data4" },
                { "mData": "Data5" }
             ]
          });
       });
    }
    
    0 讨论(0)
提交回复
热议问题