Start Building Professional
Web Apps Today


 
Categories Question details Back To List
Question  posted by udhayabalachandar on Apr 05, 2008 03:09
open dhtmlx forum
how to delete a row in grid using Keyboard delete key

How to delete a row in a grid using the Keyboard delete key and it must update in database. I want to implement in JSP page..
I dont want strike out rows when I delete the row... It should be hide in Grid... when I click the save button the records should be saved in database, without deleted records

Please help me ASAP


Regards
Udhayabalachandar
Answer posted by Support on Apr 07, 2008 01:55
>>How to delete a row in a grid using the Keyboard delete key

You can attach any custom code to onKeyPress event, or extend used keymap by next code

dhtmlXGridObject.prototype._key_events.k46_0_0=function(){  
    if (!this.editor && this.row) this.deleteRow(this.row.idd);
}

>>I dont want strike out rows when I delete the row..
In dhtmlxdataprocessor.js you can replace next line
        self.obj.setRowTextStyle(rowId,"text-decoration : line-through;");
with
       self.obj.setRowHidden(rowId,true);
Answer posted on Apr 07, 2008 03:46
How to deleted block of rows..
if suppose we select a 1,2,3,4,5 rows in grid and press delete button... It doesnt delete the whole rows from 1,2,3,4,5...It delete the 5th row only..

Please guide me in this problems.


Regards
Udhayabalachandar
Answer posted by Support on Apr 07, 2008 05:59
Instead of
   if (!this.editor && this.row) this.deleteRow(this.row.idd);
you can use
    if (!this.editor) this.deleteSelectedRows();
Answer posted on Apr 11, 2008 00:07
I want to display the confirm message box when delete key pressed....
I am using Dataprocessor for Delete Action.
Once I click ok in the confirm box then the Selected Rows in the Grid is deleted and simultaneously updated in Database also

If click close the confirm box or cancel in Confirm box window the Selected rows should not be deleted in the Grid...



Please Help me ASAP

Thanks and Regards
Udhayabalachandar.C
Answer posted by Support on Apr 11, 2008 01:25
Can be done with onBeforeRowDeletedevent

grid.attachEvent("onBeforeRowDeleted",function(){
    return confirm("Are you sure?");
});
Answer posted on Apr 11, 2008 03:07

This is my Coding

 

 mygrid = new dhtmlXGridObject('gridbox');
 mygrid.enableAlterCss("even","uneven");

 mygrid.setOnKeyPressed(onKeyPressed);

 mygrid.enableMultiselect(true);
 mygrid.init();
  mygrid.loadXML("statusMaintenance.do?method=loadWbsData");
  mygrid.enableUndoRedo();

 function onKeyPressed(code,ctrl,shift){
   
    if(code==67&&ctrl){
      if (mygrid.editor) return true;
     var ids=mygrid.getSelectedRowId().split(",");
     mygrid._cp_buffer=ids.reverse();
    }
    if(code==86&&ctrl){
      if (mygrid.editor) return true;
     if (mygrid._cp_buffer){
      var target=mygrid.getSelectedRowId().split(",")[0];
      for (var i=0; i < mygrid._cp_buffer.length; i++) {
       var id=mygrid._cp_buffer[i];
       mygrid.moveRowTo(id,target,"copy","sibling");
      };
      mygrid._cp_buffer=null;
     }
    }
  return true;
    }
   
  
   
     myDataProcessor = new dataProcessor("sms/update.jsp?action=data");
    myDataProcessor.enableDataNames(true);
    myDataProcessor.setUpdateMode("off");//available values: cell (default), row, off
    myDataProcessor.defineAction("error",myErrorHandler);
 myDataProcessor.setTransactionMode("GET");
 myDataProcessor.init(mygrid);

 function myErrorHandler(obj){
  alert("Error occured.\n"+obj.firstChild.nodeValue);
  myDataProcessor.stopOnError = true;
  return false;
 }

 

This is my deleted code for Selected Rows..

dhtmlXGridObject.prototype._key_events.k46_0_0=function(){ 
    if (!this.editor) this.deleteSelectedRows();
   
    //this.deleteRow(this.row.idd);
     var sel=mygrid.getSelectedId();
    if (!sel) return;

    mygrid.deleteRow(sel);
   
 }

if I paste your code before the next this if loop

grid.attachEvent("onBeforeRowDeleted",function(){
    return confirm("Are you sure?");
});

Is It correct.. Where I can paste your code..

If suppose I selected 1,2,3,4,5 and press delete button.. only one confirm message should be displayed

How can I do this in my code?

 

Thanks and Regards

Udhaya

 

 

 

 

 

Answer posted by Support on Apr 11, 2008 05:02
>>Where I can paste your code..
Anywhere after grid.init

mygrid.init();
grid.attachEvent("onBeforeRowDeleted",function(){
    return confirm("Are you sure?");
});

>>If suppose I selected 1,2,3,4,5 and press delete button.. only one confirm message should be displayed
In described scenario the confirmation will be shown 5 times
If you need to have a single confirmation, you can use next code instead


     var sel=mygrid.getSelectedId();
    if (!sel) return;    
    if (confirm("Are you sure?")) mygrid.deleteRow(sel);
Answer posted by Udhayabalachandar on Apr 15, 2008 03:29


  dhtmlXGridObject.prototype._key_events.k46_0_0=function(){ 
  if (!this.editor)
     if (confirm("Are you sure?")) this.deleteSelectedRows();
   }

 

This is my Delete code in my Grid.. I have one combo box... The Grid is Loading for the Corresponding combox box value.. In the Onload the Grid delete is working when Delete key is pressed...

If I change the Combo box value and the Grid is loaded and I click the selecte one row and Click the Delete button the Row is not Deleted...

 

What should be the problem.. Please suggest me some solution

thanks and Regards

Udhayabalachandar

 

 

Answer posted by Support on Apr 15, 2008 04:26
This described logic row must delete in any case, when grid in not edit state.
It possible that you have reloaded grid while it was in edit state, and while new data loaded, grid still preserve old edit state.
Please try to add next command before reloading grid with new data
    grid.editStop();