【发布时间】:2019-06-29 06:17:17
【问题描述】:
我正在尝试通过对控制器的 ajax 调用加载数据表。 在调用 ajax 时 .. 它会执行并返回数据,但在控制台中会出现“无法读取未定义的属性 'style'”这样的错误。
我正在尝试以下代码
var editor; // use a global for the submit and return data rendering in the examples
//$(document).ready(function () {
debugger;
editor = new $.fn.dataTable.Editor({
ajax: "PRC/PRCGenerate",
table: "#example",
fields: [{
label: "PQTY",
name: "PQTY"
}, {
label: "PRCReadyDT",
name: "PRCReadyDT"
}, {
label: "REMARKS:",
name: "REMARKS"
}
]
});
// Activate an inline edit on click of a table cell
$('#example').on('click', 'tbody td.editable', function (e) {
editor.inline(this);
});
$('#example').DataTable({
dom: 'Bfrtip',
ajax: 'PRC/PRCGenerate',
columns: [
{
data: null,
defaultContent: '',
className: 'select-checkbox',
orderable: false
},
{ data: 'OANO' },
{ data: 'ID' },
{ data: 'PONO' },
{ data: 'POLI' },
{ data: 'MOULDCODE' },
{ data: 'DESCRIPTION' },
{ data: 'Drg' },
{ data: 'Rev' },
{ data: 'METALCODE' },
{ data: 'METALNAME' },
{ data: 'WEIGHT' },
{ data: 'QTY' },
{ data: 'PQTY', className: 'editable' },
{ data: 'Machining' },
{ data: 'PRC' },
{ data: 'DELIVERYDT' },
{ data: 'PRCReadyDT', className: 'editable' },
{ data: 'PRCNO' },
{ data: 'REMARKS', className: 'editable' }
//render: $.fn.dataTable.render.number(',', '.', 0, '$'),
],
select: {
style: 'os',
selector: 'td:first-child'
},
buttons: [
{ extend: 'create', editor: editor },
{ extend: 'edit', editor: editor },
{ extend: 'remove', editor: editor }
]
});
//});
<script src="https://cdn.datatables.net/select/1.2.7/js/dataTables.select.min.js"></script>
<script src="https://cdn.datatables.net/select/1.2.7/js/dataTables.select.min.js"></script>
<script src="https://cdn.datatables.net/buttons/1.5.4/js/dataTables.buttons.min.js"></script>
<script src="https://cdn.datatables.net/1.10.19/js/jquery.dataTables.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
@model IEnumerable<RedICMVC.Models.sp_PRC_Record_Result>
<div class="card">
<table id="example" class="table display">
<thead>
<tr>
<th>
@Html.DisplayNameFor(model => model.OANO)
</th>
<th>
@Html.DisplayNameFor(model => model.ID)
</th>
<th>
@Html.DisplayNameFor(model => model.PONO)
</th>
<th>
@Html.DisplayNameFor(model => model.POLI)
</th>
<th>
@Html.DisplayNameFor(model => model.MOULDCODE)
</th>
<th>
@Html.DisplayNameFor(model => model.DESCRIPTION)
</th>
<th>
@Html.DisplayNameFor(model => model.Drg)
</th>
<th>
@Html.DisplayNameFor(model => model.Rev)
</th>
<th>
@Html.DisplayNameFor(model => model.METALCODE)
</th>
<th>
@Html.DisplayNameFor(model => model.METALNAME)
</th>
<th>
@Html.DisplayNameFor(model => model.WEIGHT)
</th>
<th>
@Html.DisplayNameFor(model => model.QTY)
</th>
<th>
@Html.DisplayNameFor(model => model.PQTY)
</th>
<th>
@Html.DisplayNameFor(model => model.Machining)
</th>
<th>
@Html.DisplayNameFor(model => model.PRC)
</th>
<th>
@Html.DisplayNameFor(model => model.DELIVERYDT)
</th>
<th>
@Html.DisplayNameFor(model => model.PRCReadyDT)
</th>
<th>
@Html.DisplayNameFor(model => model.PRCNO)
</th>
<th>
@Html.DisplayNameFor(model => model.REMARKS)
</th>
</tr>
</thead>
</table>
</div>
【问题讨论】:
-
可能你的
jquery在成功的ajax 调用之前就已经运行了。所以他们没有得到td。您可以尝试使用setTimeout函数或在ajax 调用后运行该函数。 -
我必须在哪里写 setTimeout.?
-
可能是因为你没有
td标签
标签: javascript jquery asp.net-mvc-4 datatables