一个 Datatables.net 表,其中包含来自 Sharepoint 2010 REST API 的多个 ajax 调用 [英] One Datatables.net table with multiple ajax calls from Sharepoint 2010 REST API

查看:15
本文介绍了一个 Datatables.net 表,其中包含来自 Sharepoint 2010 REST API 的多个 ajax 调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新来的,所以请提前原谅我这个冗长的问题.我是 SP2010 的新手,到目前为止按照以下教程使 JQuery Ajax 调用我的 SP 列表:谁需要数据视图 Web 部件?SharePoint REST 和 DataTables.net

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 Needs a Data View Web Part? SharePoint REST and DataTables.net

我(和所有人)的问题是,SP2010 listdata.svc 仅返回 JSON 中的前 1000 个条目.但是,教程建议使用一种预过滤方法来仅调用用户需要的数据,就我而言,我想将所有 200 多个条目加载到表中,然后让用户选择/过滤他/她要.

My (and everybody's) problem is, that SP2010 listdata.svc returns only the first 1000 entries in the JSON. However the tutorial suggest a pre-filtering method to call for only the data the user would need, in my case, I would like to load all my 200+ entries to the table, and then let the user to select/filter whatever he/she wants.

我设法进行了两次 Ajax 调用(一个具有前 1000 个条目,另一个具有 2000 个以上的其余条目 - 用于测试,以便于查看,其中哪些进入了表格),并且在调试器中,两个 GET 请求都发出并返回状态 200-OK,以及数据,但只有其中一个被加载到表中.

I managed to make the two Ajax calls (one with first 1000 entries, and the other with the rest above 2000 - for testing, to make it easy to see, which of them made into the table), and in debuggers both GET requests go out and come back with status 200-OK, and the data, but only one of them are loaded into the table.

问题: 是否有任何方法可以在传递给Datatable之前组合返回的jqXHR响应,或者是否有任何设置,在表初始化后,第二个数据不会覆盖第一个一?我知道,对于大多数人来说,多次 ajax 调用是不行的",但在我的情况下,由于我的服务器速度和表的使用频率,这不是问题,但到目前为止我找到了解决方案填充多个表的多次调用的主题.

The question: Are there any methods to combine the returning jqXHR responses before passing to the Datatable, or is there any setting, that after the table initialization, the second data doesn't overwrite the first one? I know, that the multiple ajax calls are a "no go" for most, but in my case, it is not a problem due to the speed of my server, and the usage frequency of the table, but so far I found solutions in the topic of multiple calls to populate multiple tables.

到目前为止我的代码:

<script type="text/javascript">
function LoadData()
{
var call = $.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"
            }       
        });
		
 (call, call2).done(function (data,textStatus, jqXHR){
            	$('#example')
					.on('xhr.dt', function ( e, settings, json ) {
					for ( var i=0, ien=json.aaData.length ; i<ien ; i++ ) {
					json.aaData[i].sum = json.aaData[i].one + json.aaData[i].two;
					}
					// Note no return - manipulate the data directly in the JSON object.
					} )
				.dataTable({
					ajax: "data.json",
                       	"bServerside" : true,
						"bProcessing": false,
						"aaData": data.d.results,
						"aoColumns": [
							{ "mData": "Data1" },
							{ "mData": "Data2" },
							{ "mData": "Data3" },
							{ "mData": "Data4" },
							{ "mData": "Data5" }
							],
							"bRetrieve": true,
				//	"initComplete": function(settings, json) {
				//	alert( 'DataTables has finished its initialisation.' );
				//			}
							});

			call.fail(function (jqXHR,textStatus,errorThrown){
            alert("Error retrieving Tasks: " + jqXHR.responseText);

});
});
}
</script>

预先感谢您提供如何解决此问题的任何建议.

Thanks in advance to any suggestions how to tackle this.

推荐答案

如果你无法避免每次 Ajax 调用 1000 条记录的限制,你可以使用下面的代码.

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

当两个 Ajax 调用都成功时,它使用 $.when 来执行回调.>

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" }
         ]
      });
   });
}

这篇关于一个 Datatables.net 表,其中包含来自 Sharepoint 2010 REST API 的多个 ajax 调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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