问题描述
var t = $('#myDataTable').DataTable({
"scrollX": true,"scrollY": true,columnDefs: [
{//ProductName
targets: 0,className: 'text-left'
},{//Code
targets: 1,className: 'text-center'
},{//Quantity
"render": $.fn.dataTable.render.number(',','.',4),"targets": 2,className:'text-right'
}
]
});
$('#myDataTable tbody').on('click','tr',function () {
if ($(this).hasClass('selected')) {
$(this).removeClass('selected');
}
else {
t.$('tr.selected').removeClass('selected');
$(this).addClass('selected');
}
});
我要实现的是,当用户单击“生成草稿发票”(如附件中所示)时,“数量”列中的值将从1234开始更新,仅在所选行中。并非所有行。
这是我正在尝试做的,但是不起作用:(
$('#GenerateDraftInvoice').click(function () {
t.row('.selected').$(this).parents('tr').data()[4].text('1234');
});
注意:为了方便理解,我简化了代码。When The User Clicks on The Generate Draft Invoice Button as show in the picture. The quantity value in the selected row (RowNo: 2) will get change to 1234. I have shortened my code for easy understanding of the reviewer.
先谢谢了。保持安全:)
解决方法
假设数量是第三列。
$('#GenerateDraftInvoice').click(function () {
$('tr.selected').children().eq(2).text('1234');
});
.eq()
从0
开始,并且.data()
与data-modal
之类的属性一起使用
ps。我不确定GenerateDraftInvoice的按钮的位置,但是如果将其附加到行,则代码将更改为
$('#GenerateDraftInvoice').click(function () {
$(this).parent().siblings().eq(2).text('1234');
});