Start Building Professional
Web Apps Today


 
Categories Question details Back To List
Question  posted by rtabassum on Feb 01, 2009 04:14
open dhtmlx forum
change row color on click of check box

Hi in my application the xml file is created at runtime(which contains checkbox inone of the cell) after getting loaded in the grid and once the user check the checkbox i want the color of the row to change it should show that it got selected by changing the complete row's color how do i change the row color on check of a checkbox existing in that row.
Answer posted by dhxSupport on Feb 02, 2009 03:38
You can use "onCheck" event:
mygrid.attachEvent("onCheck",funtion(rowId,cellInd,state){
   mygrid.setRowTextStyle(rowId,"background-color: red");
});
Answer posted on Feb 02, 2009 04:07
This will change the color though the check box is checked or not checked i mean once the check box is clicked it is changing the color but i want to change the color when the check box is checked and brig back to normal color when the check box is unchecked, how could i do this please suggest me.
Answer posted by dhxSupport on Feb 02, 2009 06:00
The following code will change color of a row depends on the status of the checkbox:

mygrid.attachEvent("onCheck",function(rowId,cellInd,state){
            if (state){
                mygrid.setRowTextStyle(rowId,"background-color: red;");
            }
            else {
                mygrid.setRowTextStyle(rowId,"background-color: #fff");
            }
        });
Variable "state" returns true if checkbox is checked.
The following code will change color for all checked rows after grid loading:
mygrid.loadXML("grid.xml",function(){
                var cellInd=4;
                debugger;
                mygrid.forEachRow(function(id){
                    if (mygrid.cellById(id,cellInd).isChecked()){
                        mygrid.setRowTextStyle(id,"background-color: red;");
                    }
                })
            });
cellInd - index of a column with checkboxes.