[英]How to pass multiple parameters in columns.render function in Datatables jquery?
I have data below and I want to pass two variables (id, name) in the columns.render function in Datatables.我在下面有数据,我想在列中传递两个变量(id、名称)。在数据表中渲染 function。
What I have now is only pass the id in the render function.我现在只在渲染 function 中传递 id。 I also want to pass name in the render function.
我还想在渲染 function 中传递名称。
Thanks.谢谢。
const myData = [
{ id: 2, name: "book" },
{ id: 5, name: "song" },
];
$("#example").DataTable({
data: myData,
columns: [
{
targets: 1,
data: "id",
render: function (data, type, row, meta) {
return (
"<button class='btn btn-default' data_id='" +
data + //id is passed to here
"'>" +
"name" + //the name I want to pass to here.
"</button>"
);
},
},
],
});
You can do it using the row
parameter of render
function.您可以使用
render
function 的row
参数来完成。
const myData = [
{ id: 2, name: "book" },
{ id: 5, name: "song" },
];
$("#example").DataTable({
data: myData,
columns: [
{
targets: 1,
data: "id",
render: function (data, type, row, meta) {
return (
"<button class='btn btn-default' data_id='" +
data + //id is passed to here
"'>" +
row.name + //get the name using row parameter
"</button>"
);
},
},
],
});
More details about render function can be found at https://datatables.net/reference/option/columns.render有关渲染 function 的更多详细信息,请访问https://datatables.net/reference/option/columns.render
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.