I am totally frustrated this must be a bug no other way around it. Delete provided by the code given doesn’t work. Method getSelectedId() always returns null when being called in the delete function. I think it has something to do with the event on clicking in the grid. For a work around I tried setting a global variable to get the row ID in the method doOnRowSelected() and then using that variable in the delete function for the method mygrid.deleteRow(id). If I add an alert() method before the delete method it works but when I remove it it doesn’t. I was using the alert to check the value and its seems that is the only time the deleteRow() method will work.
NOTE**
It seems to be a timing issue because when I add
setTimeout(function(){mygrid.deleteRow(id);}, 2000);
the deleteRow() then seems to work. What is the real issue at hand I can leave the delay in but it seems kind of hackish… Any help would be a great help.
var id = null; <----- GLOBAL I AM USING
$('#add_user').live('click', function(){
var newId = (new Date() ).valueOf();
mygrid.addRow(newId,"*-NAME-*,*-ADDRESS-*,*--*,*-*,***,***,***,***",mygrid.getRowsNum());
mygrid.selectRow(mygrid.getRowIndex(newId),false,false,true);
});
$('#clients').live('click', function(){
mygrid = new dhtmlXGridObject('gridbox');
mygrid.setImagePath("dhtmlxSuite/dhtmlxGrid/codebase/imgs/");
mygrid.setHeader('<h2 style="text-align:center;">Name</h2>,<h2 style="text-
align:center;">Addess</h2>,<h2 style="text-align:center;">Town</h2>,
<h2>Phone</h2>,<h2>Cell</h2>,
<h2>Contact Pref</h2>,<h2>Email</h2>,<h2>Grant Site Usage</h2>,<h2>User
Name</h2>,<h2>Password</h2>,<h2>Smart Phone</h2>');
mygrid.setInitWidths("120,153,100,100,117,140,120,100,100,100");
mygrid.setColAlign("left,left, left,center,right,center,right,center,right,center,right");
mygrid.setColTypes("ed,ed,ed,ed,ed,ed,ed,ch,ro,ed,ed");
mygrid.setColSorting("db_connector,connector,connector,connector,connector,
connector,connector,connector");
mygrid.setSkin("dhx_blue");//set grid skin
mygrid.attachHeader('#connector_text_filter,#connector_text_filter,#connector_text_filter,
<button id="delete_row">Delete Client</button>,<button id="add_user" >
Add Client</button>');
mygrid.attachEvent("onEditCell", doOnCellEdit);
mygrid.attachEvent("onRowSelect",doOnRowSelected);
mygrid.init();
mygrid.loadXML('db_connector.php');
var dp = new dataProcessor('db_connector.php');
dp.init(mygrid);
});
$('#delete_row').live('click',function(){
//alert(mygrid.getSelectedId()); <-- THIS RETURNS NULL
//alert(id); <---------------- ONLY WORKS IF THIS IS CALLED ?????
setTimeout(function(){mygrid.deleteRow(id);}, 2000); //<-- Timing issue WORKS when delay is used.
mygrid.deleteRow(id);
return true;
});
function doOnRowSelected(rowID,celInd){
id = mygrid.getSelectedId(); <------- MY WORK AROUND
return true;
};
function doOnCellEdit(){
var cell = mygrid.getSelectedCellIndex();
if(cell === 6){
var row = mygrid.getSelectedId();
var value = mygrid.cells(row, cell).getValue();
mygrid.cells(row, 8).setValue(value);
}
return true;
};