ParamQuery grid support forum

General Category => Help for ParamQuery Pro => Topic started by: hyh888 on November 19, 2021, 04:56:07 pm

Title: DELETE problem
Post by: hyh888 on November 19, 2021, 04:56:07 pm
When I select a row in treegrid and press DELETE ,all data in grid are deleted.
When I select a row in grid and press DELETE in common grid, the data in the row(s) are deleted, but the empty row is still there. Is it possible to delete whole row (or rows)?
Title: Re: DELETE problem
Post by: paramvir on November 19, 2021, 06:31:59 pm
whole row(s) can be deleted by using deleteNodes or deleteRow API method.

https://paramquery.com/pro/api#method-deleteNodes

https://paramquery.com/pro/api#method-deleteRow

Example: https://paramquery.com/pro/demos -> context row -> Delete Row.
Title: Re: DELETE problem
Post by: hyh888 on November 19, 2021, 07:33:53 pm
Than you for the help. But I hope pqgrid can fix two problems that I have described . They really make trouble.
Title: Re: DELETE problem
Post by: paramvir on November 19, 2021, 08:56:16 pm
Sure thanks for pointing out the issue in treegrid, it would be fixed in upcoming version.

As far as pressing delete key in grid is concerned it's the default behaviour of delete key to clear data in row which can be customized with help of beforeCellKeyDown event.

https://paramquery.com/pro/api#event-beforeCellKeyDown
Title: Re: DELETE problem
Post by: hyh888 on November 20, 2021, 03:10:54 am
Maybe this is  the best solution now.
When I put some code in beforeCellKeyDown event, it is a little troublesome to get rowIndx list of the rows selected.
Only the last row (in selected rows) can be deleted easily. Is there any easy way to delete all selected rows?

if(event.key=="Delete" ){debugger;
//var Sel = this.Selection().getSelection();//There need be a For Cyclic Sentence to remove the repeated rowindexs.
this.deleteRow({ rowIndx:ui.rowIdx } );
}
Title: Re: DELETE problem
Post by: paramvir on November 20, 2021, 11:03:50 am
eachRow method can be used to get unique rows in the Selection.

Code: [Select]
var nodes = [];
var Sel = this.Selection().eachRow(function(rowData){
  nodes.push(rowData);
})
this.deleteNodes(nodes);
return false; //to prevent default behaviour.

https://paramquery.com/pro/api#method-Range

https://paramquery.com/pro/api#method-deleteNodes
Title: Re: DELETE problem
Post by: hyh888 on November 20, 2021, 01:23:13 pm
Thank you, it works.
Title: Re: DELETE problem
Post by: hyh888 on January 12, 2022, 02:56:19 pm
I found a new problem, when I seclected a cell and press delete key( after adding your code in grid), the whole row is deleted.  I hope that only when the whole row is selected and del-key is pressed then to delete the whole row. Would you like kindly to show me how to fix it?
Title: Re: DELETE problem
Post by: paramvir on January 12, 2022, 06:40:00 pm
type of selection can be detected with help of API

Code: [Select]
var type = grid.Selection().address()[0].type
if(type == 'row'){
 
}
Title: Re: DELETE problem
Post by: hyh888 on January 12, 2022, 07:45:13 pm
Great! It works. Many thanks for your kindly help.