jquery - 单击一个单元格会触发该行中每个单元格的“on change”事件
问题描述
我正在为我的 datatables.net 表使用编辑器插件。
当我单击一个单元格以像这样编辑内联时:
它为每个单元格触发onChange
事件,就好像每个单元格中的值都已更改一样。
editor.field('to_date').input().on( 'change', function (e,d) {
console.log("to_date event fired")
});
这就是我创建表的方式
editor = new $.fn.dataTable.Editor( {
data: data,
table: "#adSets",
fields: [ {
name: "interest_id"
},{
name: "interest_fb_id"
},{
name: "adset_name"
}, {
name: "budget"
}, {
name: "duration",
type: "select",
options: [
{ label: 'Daily', value: 'Daily' },
{ label: 'Lifetime', value: 'Lifetime' }
]
}, {
type: "datetime",
name: "from_date",
readonly: true,
format: 'MM-DD-YYYY hh:mm A'
}, {
type: "datetime",
name: "to_date",
readonly: true,
format: 'MM-DD-YYYY hh:mm A'
}
]
} );
adSetsTable = $('#adSets').DataTable( {
data: data,
bPaginate: false,
bFilter: false,
bInfo: false,
columnDefs: [
{
targets: [ 0, 1 ],
visible: false
}
],
columns: [
{ title: "Interest Id", data: "interest_id", className: 'text-left'},
{ title: "Interest Fb Id", data: "interest_fb_id", className: 'text-left'},
{ title: "Adset Name", data: "adset_name", className: 'text-left'},
{ title: "Budget", data: "budget", className: 'text-right', render: $.fn.dataTable.render.number( ',', '.', 0, '$' ) },
{ title: "Duration", data: "duration", className: 'text-right'},
{ title: "Start Date", data: "from_date", className: 'text-right'},
{ title: "End Date", data: "to_date", className: 'text-right' }
]
} );
editor.field('from_date').disable();
editor.field('to_date').disable();
// Activate an inline edit on click of a table cell
$('#adSets').on( 'click', 'tbody td:not(:first-child)', function (e) {
editor.inline( this, {
onBlur: 'submit'
});
});
我不确定我是否以错误的方式启动了表格?
这是一个显示问题的视频,以防有人想看一看。https://streamable.com/s9fzm
它会自动失去编辑模式,因为 onChange 正在触发并且我正在调用adSetsTable.rows().invalidate().draw();
解决方案
即使使用 Datatables 库中包含的编辑功能,问题是否仍然存在?看起来可以通过 cell().edit() 函数完成单元格编辑,如此处文档中所述:
https://datatables.net/reference/api/cell().edit()
希望有帮助!
推荐阅读
- vb.net - Sql 语法在 MS Access 中有效,但在 Visual Basic 中无效
- html - 如何垂直居中元素
- python - 更改以前的输入 - Python
- python - 如何在python中将变量更改为字符串
- javascript - 使用 Mongoose 模型检查集合中是否存在文档
- python - 通过 Ajax 将数据从 Django 模板发送到 views.py
- python - Matplotlib 曲线下区域条件颜色
- reactjs - 如何在 MongoDB 中组合 3 个查询的结果?
- windows - schtasks 命令中的单引号
- python - 使用 pandas 从外部文件调用函数