我如何在不渲染DataTable的情况下使用自定义字段

时间:2019-01-28 13:39:12

标签: asp.net-core datatable .net-core asp.net-core-mvc

表中的某些列希望在不渲染的情况下使用。例如,表有五列,我想在TBODY中定义第一列和最后一列。 2-3-4列必须通过DataTable呈现

我尝试为这些列设置null,data:'',类型:'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>


0 个答案:

没有答案