首页 > 解决方案 > 我如何使用自定义字段而不在 DataTable 中呈现

问题描述

桌子上的一些列想要使用而不渲染它。例如,表有五列,我想在 TBODY 中定义第一列和最后一列。列 2-3-4 必须通过 DataTable 呈现

我已经尝试为该列设置 null, data:'' , type:'html' 但它们不起作用。总是给出关于第 0 行的错误。

    <thead>
        <tr>
            <th scope="col">
                #
            </th>
            <th scope="col">
                <label class="control-label">Loc</label>
            </th>
            <th>
                <label class="control-label">Date</label>
            </th>
            <th>
                <label class="control-label">Per</label>
            </th>
            <th>
                <label class="control-label">Type</label>
            </th>
            <th scope="col">#</th>
        </tr>
    </thead>
    <tbody>
            foreach (var item in Model)
            {
                <tr>
                    <td>
                        Always True
                    </td>
                    <td>
                    </td>
                    <td>
                    </td>
                    <td>
                    </td>
                    <td>
                    </td>
                    <td>
                        Some partial views
                    </td>
                </tr>
            }
        }
    </tbody>
</table>

<script>
    var table = $('#dataTable').dataTable({
        "processing": true,
        "serverSide": true,
        "info": true,
        "stateSave": true,
        responsive: {
            details: false
        },
        lengthMenu:
        [
            [10, 20, 50, -1], [10, 20, 50, "All"]
        ],
        ajax: {
            "url": "myUrl.json",
            "type": "POST",
            "contentType": 'application/json; charset=utf-8',
            "dataType": 'json',
            'data': function(data) {
                return JSON.stringify(data);
            },
            "error": function(xhr, error, thrown) {
                alert("error");
            }
        },
        "columns": [
            {
                //this column get from TBODY,
            }
            {
                data: 'loc',
                responsivePriority: 1
            },
            {
                data: 'date',
                responsivePriority: 5
            },
            {
                data: 'per',
                responsivePriority: 3
            },
            {
                data: 'type',
                responsivePriority: 4
            },
            {
                //This column get from TBODY because there is a partial view
            }
        ],
        rowId: "id",
        "order": [[1, "asc"]],
    });
</script>


标签: asp.net-coredatatable.net-coreasp.net-core-mvc

解决方案


推荐阅读