根据列值在动态生成的表中显示sharepoint列表项 [英] Display items of sharepoint list in a dynamically generated tables based on column value

查看:73
本文介绍了根据列值在动态生成的表中显示sharepoint列表项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试打印使用REST api以表格格式提取的列表项。但是我需要基于列值的不同表格。

I am trying to print the list items pulled using REST api in the format of tables. However I would need different table based on a column value.

例如:如果列名称是col1,并且如果有col1值为"A"的项目,那么单独的表格应为所有值为"A"的项目创建。同样适用于其他字母表。

For ex:if the column name is col1 and if there are items whose col1 value is "A", then a separate table should be created for all the items whose value is "A". And same applies for rest of the alphabets.

 参考中的表格是HTML表格。

 Table in the reference is HTML table.

这里是一个片段:

var objItems = data.d.results;

  for(var i = 0; i< objItems.length; i ++)

var objItems = data.d.results;
 for (var i = 0; i < objItems.length; i++)

{

var items = data.d.results [i];

var items = data.d.results[i];

var tablecontent ='< table id =" tab1" ;>< tr>< td> col1< / td>< td> col2< / td>< / tr>'

var tablecontent='<table id="tab1"><tr><td>col1</td><td>col2</td></tr>'

tablecontent + ='< tr>< ; td>'+ items [" col1"] +'< / td>< / tr>';

tablecontent+='<tr><td>'+items["col1"]+'</td></tr>';

tablecontent + ='< tr>< td>'+ items [" col2"] +'< / td>< / tr>< / table>';

tablecontent+='<tr><td>'+items["col2"]+'</td></tr></table>';

}

  ; $('#carsGrid')。append(tableContent);

 $('#carsGrid').append(tableContent);

< div id =" carsGrid" style =" width:100%">< / div>

<div id="carsGrid" style="width: 100%"></div>

推荐答案

您好,

如果您已经知道将用于对结果进行分组的值,您可以在这些值上发送单独的REST请求。例如:

If you already know the values your are going to use to group your results, you could send separate REST requests filtred on those values. Ex:


  • 表1:请求URL:https:// [我的服务器] / [我的网站] / _ api / web / lists / GetByTitle('我的列表')/ items?
  • Table1 : Request URL: https://[my server]/[my web]/_api/web/lists/GetByTitle('my list')/items?


filter =(col1 eq'A')
filter=(col1 eq 'A')

  • 表2:请求URL:https:// [我的服务器] / [我的网站] / _ api / web / lists / GetByTitle('我的列表')/ items?
  • Table2 : Request URL: https://[my server]/[my web]/_api/web/lists/GetByTitle('my list')/items?


filter =(col1 eq'B ')
filter=(col1 eq 'B')

如果您事先不知道这些值,则必须获取所有项目,然后在生成HTML之前按值对其进行分组。看起来您正在使用JavaScript。根据您使用的库,可以轻松完成。

If you do not know those values in advance, you have to get all the items and then group them by value before generating your HTML. It looks like you are using JavaScript. Depending on which libraries you are using, it could be easily done.

您是否还考虑过SharePoint的本机功能?您没有描述您的用例,但这可以通过分组列表视图来完成。

Have you also considered the native capabilities of SharePoint? You have not described your use case but this could be done by a grouped list view.


这篇关于根据列值在动态生成的表中显示sharepoint列表项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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