Author Topic: After filtering, DownArrow Key couldn't add new row automatically  (Read 707 times)

hyh888

  • Pro Enterprise
  • Full Member
  • *
  • Posts: 142
    • View Profile
I hope to add new row automatically, when the DownArrow Key is pressed in the last row.
Following code works well when there is no filter used. But after filtering, pressing DownArrow Key couldn't add new row automatically when the cell in last row is selected. Would you like to provide help kindly?

              beforeCellKeyDown: function( event, ui ) {
                if(event.key=="Delete" ){
                var nodes = [];
                var type = this.Selection().address()[0].type
                if(type == 'row'){
                   var Sel = this.Selection().eachRow(function(rowData){
                     nodes.push(rowData);
                   })
                   this.deleteNodes(nodes);
                   return false; //to prevent default behaviour.                    
                }             
      
            }                   
                 if(!this.isValid( { rowData: ui.rowData } ).valid)
                      {return;}
                if(event.key=="ArrowDown" && ui.rowIndx==this.getTotalRows()-1){
                        var rowIndx = this.addRow({ rowData: defaultRowData(), checkEditable: true });
                        // this.goToPage({ rowIndx: rowIndx });
                        debugger;
                        this.editFirstCellInRow({ rowIndx: rowIndx });   
      
                }
           
             },

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6310
    • View Profile
Re: After filtering, DownArrow Key couldn't add new row automatically
« Reply #1 on: January 28, 2022, 10:53:58 am »
I guess you have been using filterModel: { hideRows: true } in which case ui.rowIndx==this.getTotalRows()-1 is not always true.

Please use this.getLastVisibleRIP() instead of this.getTotalRows()-1

hyh888

  • Pro Enterprise
  • Full Member
  • *
  • Posts: 142
    • View Profile
Re: After filtering, DownArrow Key couldn't add new row automatically
« Reply #2 on: January 28, 2022, 11:02:18 am »
Great help! It works.