简体   繁体   English

格式化服务器端jQuery Datatable

[英]Formatting server side jQuery Datatable

I am trying to format the front end look of my jQuery DataTable 我正在尝试格式化jQuery DataTable的前端外观

I currently have it looking like this https://imgur.com/a/PPgL48Y 我目前看起来像这样https://imgur.com/a/PPgL48Y

I need the repeating items in each row to be remove for example in the first row there are 2 Owner 1's. 我需要删除每行中的重复项,例如在第一行中有2个所有者1。 I only want to display a single Owner 1 in that row. 我只想在该行中显示一个所有者1。

The other issue is in row 2, Url1 is followed by a comma then Url 2 but i want 另一个问题是在第2行中,Url1之后是逗号,然后是Url 2,但我要

Url1
Url2

In the row, so removing the comma and adding a new line in that col 在该行中,因此删除逗号并在该列中添加新行

My data is being collected via server side processing 我的数据是通过服务器端处理收集的

My current jQuery code 我当前的jQuery代码

<script type="text/javascript" >

         $('#result').DataTable({
            "serverSide":true,
            "filter": false,
            "orderMulti": false,
            "ajax": "DetailedSearch?handler=ServerSideDataTable",
            "columns":[
                {"data": "location", 
                 "render": function(data,type,row){
                     return row.location;
                 }
                },
                {"data": "contactAndRole", 
                 "render": function(data,type,row){
                     return data.key + " - " + data.value;
                 }},
                {"data": "server", "sortable": "false"},
                {"data": "urls", 
                 "render": function(data,type,row){
                     return row.urls + '<br>';
                 }
                }
            ],
             rowGroup:{
                dataSrc:'appName'
            }
        });

</script>

Can i add some html elements? 我可以添加一些HTML元素吗? like a br after each url, or can the table be constructed with pure html then passed onto data tables to output? 像每个网址后面的br一样,还是可以使用纯HTML构造表,然后将其传递到数据表以输出?

I've looked into the HTML templates, and standalone documentation on the data tables website but nothing seems to be helpful. 我研究了HTML模板和数据表网站上的独立文档,但似乎没有任何帮助。

The commas for the url's array are because of the default way arrays are processed to strings to be printed into the html in the dom 网址数组的逗号是由于默认方式将数组处理为字符串以将其打印到dom中的html中

You could join() them yourself using a <br> separator instead 您可以使用<br>分隔符自己join()它们

return row.urls.join('<br/>')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM