Start Building Professional
Web Apps Today


 
Categories Question details Back To List
Question  posted by Rob Brown on Aug 28, 2008 07:23
open dhtmlx forum
Select / Deslect Row in DHTMLGrid

Hi Guys

I have a grid implimentation that lists a set of records with various statuses
These Status indicate which specific actions a user can do with the record by Enabling or disabling form elements on the page

For example on item might need authorisation so selecting the record would enable the authorise button on the page

Here is my code snippet for the grid set up

mainGrid = new dhtmlXGridObject('recordgrid');
mainGrid.setImagePath("codebase/imgs/");
mainGrid.setSkin("light");
mainGrid.setOnRowDblClickedHandler(doOnRowDblClicked);
mainGrid.attachEvent("onRowSelect",doOnRowSelected);
mainGrid.enableRowsHover(true,'grid_hover');
mainGrid.init();
mainGrid.loadXMLString("<%=DataSet%>");


function doOnRowSelected(rowId)
{
getCellValue(rowId,5);
}

function doOnRowDblClicked(rowId)
{
window.open("SBS_ReviewClaimTabbed.aspx?ID="+rowId);
}

function getCellValue(rowId,columnIndex)
{
var value = mainGrid.cells(rowId,columnIndex).getValue();
document.getElementById("btn_edit").disabled = false;
}

All I need is a way to toggle a selected Row

eg
something like


mainGrid.attachEvent("onRowDeSelect",doOnRowDeSelected);

function doOnRowDeSelected(rowId)
{
resetButtons();
}

is this possible - have I missed something

cheers

Rob



Answer posted by Support on Aug 28, 2008 07:49
There is no separate onRowDeSelect event, but you can use onBeforeSelect for the same purpose

mygrid.attachEvent("onBeforeSelect",function(new_id,old_id){
if (new_id != old_id)
    alert("row "+old_id+" most probably , will be unselected");
return true;
});

Because the row may be unselected only when another row selected in grid, the snippet above will fire each time before row unselection.



Answer posted by Rob Brown on Aug 28, 2008 08:19

Ok - I agree yes you solution works provided a different row is selected -, however - what I am after is unselecting the current row without selecting a new one thus the page buttons would then reset to their preselected

conditions

I have played a little more and expanded my doOnRowSelected function to this

var selectedrow = -1;

function doOnRowSelected(rowId)

{

if ((selectedrow == -1)||(selectedrow!=rowId))

{

selectedrow=rowId;

getCellValue(rowId,5);

alert(selectedrow);

}

else

{

selectedrow = -1;

mainGrid.clearSelection;

resetButtons();

alert(selectedrow);

}

}

ie I have added a global selectedrow var that track the selected row and this works fine

except after deselection the previously selected row remains highlighted.

Any suggestions for this final piece of the puzzle :)

Cheers for your previously super fast response;

Rob

 

 

Answer posted on Aug 28, 2008 08:36

Cracked It ! - with a hybrid of your solution

mainGrid.attachEvent("onBeforeSelect",doOnBeforeSelect);

function doOnBeforeSelect(new_id,old_id)

{

if ((selectedrow == -1)||(selectedrow!=new_id))

{

mainGrid.clearSelection;

return true;

}

}

function doOnRowSelected(rowId)

{

if ((selectedrow == -1)||(selectedrow!=rowId))

{

selectedrow=rowId;

getCellValue(rowId,5);

alert(selectedrow);

}

else

{

selectedrow = -1;

resetButtons();

alert(selectedrow);

}

}

Thanks for pointing me in the right direction

 

Rob