您好我试图在我的数据表中实现内联网格编辑。它正在工作....但是我需要在其他表中实现内联编辑....所以我想为此创建一个全局函数.....
但它显示了一些错误....这是我的代码....
var slug='sales'
window.drawDataTable = function(){
"columnDefs": [
{
targets: [10,11,27,28],
render:function(data){
return moment(data).format('LLLL');
},
},
{'targets': '_all',
'createdCell': function (td, cellData, rowData, row, col) {
$(td).attr('data-pk', rowData['id']);
const key = Object.keys(rowData)[Object.values(rowData).indexOf(cellData)];
$(td).attr('data-name', key );
}},
{ targets: [0,1], className: ""},
//{targets:'_all',className:"querytruncate"},
{
"targets": [29,30],
"orderable": false
}
],
"fnDrawCallback":function(){
$('#data_table_list td').editable({
params: function(params) {
var pk = $(this).data('pk');
var name = $(this).data('name');
var data = {};
data['field'] = name;
data['value'] = params.value;
data['id'] = pk;
data['slug']=slug;
return data;
},
url: "{% url 'request_access' %}",
success : function(data) {
if (data.status == true) {
toastr.success(data.msg);
} else {
toastr.error(data.msg);
}
},
error: function () {
toastr.error('Something went wrong');
}
});
},
}
所以我尝试像这样实现......在我的core.js中
function inline(slug){
$('#data_table_list td').editable({
params: function(params) {
var pk = $(this).data('pk');
var name = $(this).data('name');
var data = {};
data['field'] = name;
data['value'] = params.value;
data['id'] = pk;
data['slug']=slug;
return data;
},
url: "{% url 'request_access' %}",
success : function(data) {
if (data.status == true) {
toastr.success(data.msg);
} else {
toastr.error(data.msg);
}
},
error: function () {
toastr.error('Something went wrong');
}
});
}
在我的 html 中
"columnDefs": [
{
targets: [10,11,27,28],
render:function(data){
return moment(data).format('LLLL');
},
},
{'targets': '_all',
'createdCell': function (td, cellData, rowData, row, col) {
$(td).attr('data-pk', rowData['id']);
const key = Object.keys(rowData)[Object.values(rowData).indexOf(cellData)];
$(td).attr('data-name', key );
}},
{ targets: [0,1], className: ""},
//{targets:'_all',className:"querytruncate"},
{
"targets": [29,30],
"orderable": false
}
],
"fnDrawCallback": inline(slug),