使用 jQuery 删除 handsontable 中的 selectedRow
remove selectedRow in handsontable using jQuery
我有一个如下图所示的手控器。选择任何一行(例如 LastName
)后,它应该永久删除该特定行。如何使用 jQuery?
实现此目的
这是我使用 afterSelection
函数编写的代码,但我不知道如何删除该行。
this.tab.handsontable({
data: self.data,
dataSchema: {
columnsexpo: null,
placeholder: null
},
colHeaders: ['Columns Export'],
rowHeaders: true,
fixedColumns: true,
fillHandle: {
autoInsertRow: false,
},
columnSorting: true,
columns: [{
data: 'columnsexpo',
readOnly: true
}, ],
stretchH: 'all',
className: "htCenter",
height: 420,
afterChange: function() {},
beforeRemoveRow: function(row, col) {
var m = this.getDataAtCell(row, 0);
var mandatory = true;
self.MandatoryFields.forEach(function(item) {
if (!_.isEmpty(m)) {
var found = m.toLowerCase().includes(item.toLowerCase());
if (found) {
mandatory = false;
}
}
});
if (!mandatory) {
return false
} else
return true;
},
afterSelection: function(r, c) {
var da = this.getDataAtRow(r);
selectedRow = "";
selectedRow = da[0];
console.log(selectedRow);
},
afterRender: function() {
if (init) {
Events.trigger("DEW:ValidRequest", 1, self.checkValid());
}
init = true;
$('#tablesortable thead th div').filter(function() {
return $(this).text() == "Columns Export";
}).popup({
title: 'Columns Export',
position: 'top center'
});
}
});
编辑
afterSelection: function(r,c,e){
var dat = this.getDataAtRow(r)
this.alter('remove_row', r, 1);
console.log(r);
},
Now after applying above function it is removing selected Row but if i select last row it is removing all previously selected row
在handsontable的选择方法后使用hot.alter('remove_row', 10, 2);
里面的。
不需要jquery。
或者,如果您想使用 jquery,请将 handsontable 实例存储在某个变量中,并在行选择时调用它。
更新 -- 在删除行之前添加了 deselectCell。删除该行后,上一行被选中,这是导致问题的原因。
afterSelection: function(r, c, e) {
this.deselectCell()
this.alter('remove_row', r, 1);
}
我有一个如下图所示的手控器。选择任何一行(例如 LastName
)后,它应该永久删除该特定行。如何使用 jQuery?
这是我使用 afterSelection
函数编写的代码,但我不知道如何删除该行。
this.tab.handsontable({
data: self.data,
dataSchema: {
columnsexpo: null,
placeholder: null
},
colHeaders: ['Columns Export'],
rowHeaders: true,
fixedColumns: true,
fillHandle: {
autoInsertRow: false,
},
columnSorting: true,
columns: [{
data: 'columnsexpo',
readOnly: true
}, ],
stretchH: 'all',
className: "htCenter",
height: 420,
afterChange: function() {},
beforeRemoveRow: function(row, col) {
var m = this.getDataAtCell(row, 0);
var mandatory = true;
self.MandatoryFields.forEach(function(item) {
if (!_.isEmpty(m)) {
var found = m.toLowerCase().includes(item.toLowerCase());
if (found) {
mandatory = false;
}
}
});
if (!mandatory) {
return false
} else
return true;
},
afterSelection: function(r, c) {
var da = this.getDataAtRow(r);
selectedRow = "";
selectedRow = da[0];
console.log(selectedRow);
},
afterRender: function() {
if (init) {
Events.trigger("DEW:ValidRequest", 1, self.checkValid());
}
init = true;
$('#tablesortable thead th div').filter(function() {
return $(this).text() == "Columns Export";
}).popup({
title: 'Columns Export',
position: 'top center'
});
}
});
编辑
afterSelection: function(r,c,e){
var dat = this.getDataAtRow(r)
this.alter('remove_row', r, 1);
console.log(r);
},
Now after applying above function it is removing selected Row but if i select last row it is removing all previously selected row
在handsontable的选择方法后使用hot.alter('remove_row', 10, 2);
里面的。
不需要jquery。
或者,如果您想使用 jquery,请将 handsontable 实例存储在某个变量中,并在行选择时调用它。
更新 -- 在删除行之前添加了 deselectCell。删除该行后,上一行被选中,这是导致问题的原因。
afterSelection: function(r, c, e) {
this.deselectCell()
this.alter('remove_row', r, 1);
}