Author Topic: DELETE problem  (Read 2087 times)

hyh888

  • Pro Enterprise
  • Full Member
  • *
  • Posts: 142
    • View Profile
DELETE problem
« 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)?

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6310
    • View Profile
Re: DELETE problem
« Reply #1 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.

hyh888

  • Pro Enterprise
  • Full Member
  • *
  • Posts: 142
    • View Profile
Re: DELETE problem
« Reply #2 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.

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6310
    • View Profile
Re: DELETE problem
« Reply #3 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

hyh888

  • Pro Enterprise
  • Full Member
  • *
  • Posts: 142
    • View Profile
Re: DELETE problem
« Reply #4 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 } );
}
« Last Edit: November 20, 2021, 04:21:17 am by hyh888 »

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6310
    • View Profile
Re: DELETE problem
« Reply #5 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

hyh888

  • Pro Enterprise
  • Full Member
  • *
  • Posts: 142
    • View Profile
Re: DELETE problem
« Reply #6 on: November 20, 2021, 01:23:13 pm »
Thank you, it works.

hyh888

  • Pro Enterprise
  • Full Member
  • *
  • Posts: 142
    • View Profile
Re: DELETE problem
« Reply #7 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?

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6310
    • View Profile
Re: DELETE problem
« Reply #8 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'){
 
}

hyh888

  • Pro Enterprise
  • Full Member
  • *
  • Posts: 142
    • View Profile
Re: DELETE problem
« Reply #9 on: January 12, 2022, 07:45:13 pm »
Great! It works. Many thanks for your kindly help.