简体   繁体   English

服务器端处理动态列

[英]Server Side Processing Dynamic Columns

Server side path provides a 404 error where path is same as used on initial loading of the table. 服务器端路径提供404错误,其中路径与初始加载表时使用的路径相同。 The table is destroyed and the columns are dynamically changed. 该表将被销毁,并且列将动态更改。

I successfully apply server side processing where I have static columns. 我成功应用服务器端处理,我有静态列。 I have previously built the table dynamically without server side processing but the load is too large now for it to handle. 我以前动态地构建了表而没有服务器端处理,但现在负载太大而无法处理。 Therefore I have moved to SQL paging with server side processing configuration but it will not load the table even thought the path is the same as it is when I initially load the table but with one static column. 因此,我已经转移到具有服务器端处理配置的SQL分页,但它不会加载表,即使路径与我最初加载表但具有一个静态列时的路径相同。 I am using version 1.10.15 due to how long I have been using the library and I have many tables that I am concerned will no longer work if I upgrade. 我使用的是版本1.10.15,因为我使用了这个库已经有多长时间了,如果我升级的话,我有很多我不关心的表格。 Not sure upgrading will fix the problem either. 不确定升级是否也能解决问题。

JQuery Datatables code JQuery Datatables代码

var oTable = $("#InvoiceProcessing").DataTable({
                jQueryUI: true,
                pagingType: "full_numbers",
                responsive: true,
                "scrollX": true,
                "bServerSide": true,
                "sAjaxSource": "@Url.Action("GetInvoiceProcessing", "InvoiceProcessing")?clientId=" + cId + "&summaryDate=" + sumDate + "&processedDate=" + procDate + "&accountNumber=&invoiceNumber=",
                "bProcessing": true,
                "destroy": true,
                lengthMenu: [[25, 50, 100], [25, 50, 100]],
                "autoWidth": true
            });

C# method signature - This method does not get hit C#方法签名 - 此方法不会被命中

public async Task<ActionResult> GetInvoiceProcessing(Guid? clientId, DateTime? summaryDate, DateTime? processedDate, DataTableParamModel param, string accountNumber = "", string invoiceNumber = "")

I need to have the paging reflect the full size of the query. 我需要让分页反映查询的完整大小。 I am using sql paging which returns a total record count and only the page length of data. 我正在使用sql分页,它返回总记录数,只返回数据的页长。 If I can accomplish this without server side processing I would be happy with that as well. 如果我能在没有服务器端处理的情况下完成此任务,我也会对此感到满意。

I was able to use the information Priyank Panchal supplied but modifying the solution in the suggestion to meet my needs. 我能够使用提供的Priyank Panchal信息,但在建议中修改解决方案以满足我的需求。

I was not able to use it as is because the columns I generate for the grid are dynamically driven by the data and therefore cannot be predefined before loading. 我无法按原样使用它,因为我为网格生成的列是由数据动态驱动的,因此在加载之前无法预定义。

Do to that I have to load the grid three different ways. 我必须以三种不同的方式加载网格。

  1. First I load it with only one field that identifies it's usage with the Datatables default message of "No Available Records". 首先,我只使用一个字段加载它,使用Datatables默认消息“No Available Records”来识别它的用法。
  2. The second load recreates the grid after a selection of the client, which is what determines the fields required, and it reloads with the proper structure. 第二个加载在选择客户端之后重新创建网格,这是确定所需字段的内容,并使用适当的结构重新加载。
  3. Lastly, I reload the grid with another selection by the user that defines how the data is filtered. 最后,我重新加载网格,用户定义了如何过滤数据的另一个选择。

With this there is also the requirement to hide the first column, which I do through the "columnDefs" attribute of the Datatables configuration. 有了这个,还需要隐藏第一列,我通过Datatables配置的“columnDefs”属性执行此操作。

The last requirement was to provide to additional fields for edit and delete buttons. 最后一项要求是为编辑和删除按钮提供其他字段。

This was accomplished through the "columnDefs" attribute as well along with referencing the table in the following manner: "aTargets": [oTable.columns()[0].length - 2]. 这是通过“columnDefs”属性以及以下列方式引用表来完成的:“aTargets”:[oTable.columns()[0] .length - 2]。 This provided the ability to add it first to last column and another after it. 这提供了将其首先添加到最后一列而另一列添加到其后的功能。

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

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