ParamQuery grid support forum
General Category => Help for ParamQuery Pro => Topic started by: omerix on January 16, 2025, 07:21:19 pm
-
Hello,
I can perform various operations when adding rows using the addRow method. However, sometimes I use copy-paste to add multiple rows, and in this case, the addRow method is not triggered.
I tried using the beforePaste event, but it executes for all rows, including the existing ones that are not newly added.
What I need is an event that triggers only when a new row is added to the grid, whether through addRow or paste functionality. Is there something like a beforeRowAdd event or any alternative to achieve this?
This function "GridNew()" assigns default values to new rows.
I use it to add new rows and set default values for them, but it does not work for rows added via paste.
The goal is to make it work for rows added through paste as well.
window.GridNew = function () {
function applyDefaultValues(rowData) {
var defaultValues = { type: 1, code: 'newCode',quantity:1 };
return Object.assign({}, defaultValues, rowData);
}
// Adding a new row
var newRowData = applyDefaultValues({}); // Apply default values
if (localStorage.getItem('qpRowBottom') == 1) {
// Adding a new row at the bottom
var pm = grid.option("pageModel");
grid.option("pageModel", { type: 'local', curPage: 1, rPP: pm.rPP, rPPOptions: pm.rPPOptions });
var rowIndx = grid.addRow({
newRow: newRowData,
track: true,
history: false,
checkEditable: false,
refresh: true
});
console.log("New row added: Bottom");
grid.goToPage({ rowIndx: rowIndx });
grid.editFirstCellInRow({ rowIndx: rowIndx });
} else {
// Adding a new row at the top
var rowIndx = grid.addRow({
rowIndxPage: 0,
newRow: newRowData,
track: true,
history: false,
checkEditable: false,
refresh: true
});
console.log("New row added: Top");
grid.editFirstCellInRow({ rowIndx: rowIndx });
}
};
Thank you for your help!
-
beforeValidate and change are universal events which fire irrespective of the origin.
https://paramquery.com/pro/api#event-beforeValidate
https://paramquery.com/pro/api#event-change
ui.addList length can be checked in the event listener for newly added rows.
-
I just discovered rowTemplate and managed to use it to set default values for rows added with paste. I even removed the default value assignment from addRow as it was no longer needed.
It seems that rowTemplate does not affect my existing rows because I set the default values to '' or 0 in the dataModel.
I will still take a look at beforeValidate and change things as you suggested. Thanks for the suggestion!
-
If your only goal is to set default values for newly added rows, then rowTemplate is the right fit.