Author Topic: nextEdit  (Read 3379 times)

arbyter

  • Pro Ultimate
  • Newbie
  • *
  • Posts: 43
  • Retired IT Guy
    • View Profile
nextEdit
« on: May 09, 2019, 03:24:32 pm »
hi
i am looking for a method to perfom nextEdit when the down-key  is pressed. onSave: nextEdit  works just in the same row.
Any hint?
Thank you

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6309
    • View Profile
Re: nextEdit
« Reply #1 on: May 10, 2019, 10:32:30 pm »
editorKeyDown event could be used, it would also require boundary checks.

Code: [Select]
editorKeyDown: function(evt, ui){
var grid = this;
if(evt.keyCode == 40){ //down key.

setTimeout(function(){
//debugger;
ui.rowIndx ++;
ui.rowIndxPage++;
grid.editCell(ui);
},10)
}
}

arbyter

  • Pro Ultimate
  • Newbie
  • *
  • Posts: 43
  • Retired IT Guy
    • View Profile
Re: nextEdit
« Reply #2 on: May 16, 2019, 11:08:37 pm »
thank you, it works fine. But i have another question, i am stuck on it:
not all records are ediatable in the list, just the ones that belong to me. So i added a class editable to the pq_rowcls and 
var colModel= [
   ...   {title: "Vorname",dataType:"string",dataIndx: "vorname",editable:function (ui){return ui.rowData.pq_rowcls && ui.rowData.pq_rowcls.indexOf("editable")!=-1}},
        {title: "Name",dataType:"string",dataIndx: "name",editable:function (ui){return ui.rowData.pq_rowcls && ui.rowData.pq_rowcls.indexOf("editable")!=-1}},
   ...     
  ]

i altered your snipped so:
        editorKeyDown: function(evt, ui){           
                var grid = this;
                if(evt.keyCode == 40 || evt.keyCode == 38){ //down key.
                   
                    setTimeout(function(){
                        //debugger;
                        evt.keyCode==40 ?ui.rowIndx ++:ui.rowIndx --;
                        evt.keyCode==40 ? ui.rowIndxPage++:ui.rowIndxPage--;
                        if(ui.$cell.parents('.editable'))grid.editCell(ui); <--------------------this does not work, it is not reaching the row 
                    },10)                   
                }
            }

arbyter

  • Pro Ultimate
  • Newbie
  • *
  • Posts: 43
  • Retired IT Guy
    • View Profile
Re: nextEdit
« Reply #3 on: May 17, 2019, 02:51:15 pm »
hi
i think, triggering a dblclick event could be the most elegant way to achieve my goal. (invoke editor just on admitted rows)
but no look.
my snippet:
if(evt.keyCode == 40 || evt.keyCode == 38){ //down key.               
                    setTimeout(function(){
                        //debugger;
                        evt.keyCode==40 ?ui.rowIndx ++:ui.rowIndx --;
                        evt.keyCode==40 ? ui.rowIndxPage++:ui.rowIndxPage--;
                        ui.$cell.dblclick() //does not work, tried also .trigger('dblclick')
                    },10)                   
                }

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6309
    • View Profile
Re: nextEdit
« Reply #4 on: May 20, 2019, 12:34:41 pm »
ui.$cell.dblclick() logic is incorrect since it's the same cell in which key is pressed down.

you could put increment/decrement logic in a do/while loop and use isEditable method to decide edit-ability of cell. break out of the loop when editable cell is found.

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

and finally use editCell method to edit cell.

grid.editCell(ui)
« Last Edit: May 20, 2019, 12:36:36 pm by paramquery »

arbyter

  • Pro Ultimate
  • Newbie
  • *
  • Posts: 43
  • Retired IT Guy
    • View Profile
Re: nextEdit
« Reply #5 on: May 20, 2019, 08:30:34 pm »
if(grid.isEditable({rowIndx:ui.rowIndx,colIndx:ui.colIndx}))grid.editCell(ui)
did the trick
thank you