DataTables Server‑Side with deferRender: Hidden Columns Payload Handling
0 reputation · 28 Apr 2024, 04:02 UTC
0 reputation · 28 Apr 2024, 04:02 UTC
The goal is to understand how DataTables processes hidden columns when deferRender is enabled in server‑side mode. In this configuration, the client still receives the full data array from the server, but columns marked visible: false may appear as empty cells.
Current documentation does not specify whether DataTables automatically removes hidden columns from the payload or whether the server must omit them. Additionally, it is unclear if deferRender influences this behavior, potentially leading to bandwidth waste or rendering quirks.
Key uncertainties remain: does DataTables strip hidden columns during server‑side rendering? If not, how are empty cells rendered for those columns? Is there a configuration option that allows the server to know which columns are hidden so it can exclude them from the JSON response?
deferRender is active?34775 reputation · 28 Apr 2024, 05:13 UTC
No. DataTables does not automatically remove hidden columns from the server-side JSON payload, and enabling deferRender does not change that behavior. The client downloads the full data array regardless of visible: false settings, and DataTables has no built-in option to tell the server which columns to omit.
deferRender only delays creation of table cell DOM nodes until a row is drawn; it does not affect the Ajax response or remove hidden-column data.columns.data. When drawn, their cells typically exist in the DOM with display: none applied.If a hidden column value is present, DataTables renders it in a hidden table cell rather than removing it. If the value is null or missing, the cell appears empty or uses defaultContent, just like any other column. The column remains part of the row’s data model even though it is not visible.
visible: false columns are still present in data.table.cell({ row: idx, column: hiddenIdx }).data() to verify hidden-column data is available client-side after draw.columns[i].visible is sent to the server.Because DataTables cannot signal hidden columns to the server, handle omission server-side or reduce the columns.data set. If your server needs visibility state, append it with ajax.data:
ajax: {
data: function (d) {
d.hiddenColumns = table.columns().visible().toArray();
}
}Do not omit array elements for hidden columns while keeping integer columns.data indexes, or subsequent columns will shift and display wrong data.
Confirm whether your DataTables version sends columns[i].visible in the server-side request. If it does not, the server cannot know which columns are hidden without a custom ajax.data payload.
Use comments to ask for clarification. Post a solution as an answer.
34,775 reputation · 28 Apr 2024, 15:10 UTC
With server-side processing the JSON payload is built entirely by the server. visible: false and deferRender: true are client-side rendering controls only.
deferRender defers creation of DOM nodes until a row is shown; it does not change the shape of the data array received from the server. Hidden columns are kept in DataTables’ internal cache and simply omitted from the table body during draw.
Because the default Ajax request does not transmit column visibility state, the server has no way to know which columns are hidden unless you add a custom parameter. Omitting fields server-side therefore requires an explicit contract and careful index mapping to avoid breaking columnDefs and orthogonal data.