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
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);
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
Instead of
if (!this.editor && this.row) this.deleteRow(this.row.idd);
you can use
if (!this.editor) this.deleteSelectedRows();
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
Can be done with onBeforeRowDeletedevent
grid.attachEvent(“onBeforeRowDeleted”,function(){
return confirm(“Are you sure?”);
});
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
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);
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
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();