how to check/uncheck subgrid checkbox using main grid check

Hi,
i am using grid with subgrid for displaying/manupulating records. The main grid header have the check box, by check/uncheck that checkbox, it check/uncheck all checkboxs available in same column. i have achived this functionlaity using #master_checkbox filter. In subgrid also have a header checkbox, by check/uncheck that checkbox, it is  check/uncheck all the checkboxs placed in same column. This is also achieved using #master_checkbox. Now my problem is when i check/uncheck parent grid header checkbox, it should check/uncheck checkbox placed in the same column of parent grid and it should check/uncheck all the checkboxs placed in subgrid as well. But when u check/uncheck subgrid header checkbox, it should check/uncheck the sub grid column check boxes only. how to achive this? please help me

Thanks in advance,
Vel


Hello,


in this case you can use master_checkbox for sub grid.


And a checkbox with own onclick header for parent grid. When checkbox in the parent header is clicked, you can change state for each checkbox in parent grid and its subgrid:


parent.forEachRow(function(id){
parent.cells(id,INDEX).setValue(state);
});


subgrid.forEachRow(function(id){
subgrid.cells(id,INDEX).setValue(state);
});



Thanks for your reply.
But i am getting clearly. Here what is the word ‘parent’ and ‘subgrid’. what it is exactly indicats? please give example code?
Thanks.
Vel


parent is object of the parent grid and subgrid is object of the subgrid inside it.


A small example:


parent.setHeader("…,,…);





var state;


function setState(){


state = document.getElementById(“ch”).checked?1:0;


parent.forEachRow(function(id){


parent.cells(id,INDEX).setValue(state);
});
var subgrid = parent.cells(row_id,cell_index).getSubGrid();
subgrid.forEachRow(function(id){
subgrid.cells(id,INDEX).setValue(state);
});




}

Hi,
This is my code for defining my Grid.
mygrid = new dhtmlXGridObject(‘gridbox’);
    mygrid.setImagePath(“themes/General/css/images_dhtmlgrid/”);
    mygrid.setHeader(", ,IP Address,Sys Name,Interface Count,Assign Impact");
    mygrid.setInitWidths(“100,30,180,180,180,180”)
    mygrid.setColAlign(“left,left,left,left,left,left”)
    mygrid.setColTypes(“sub_row,edtxt,ro,edtxt,ro,co”);
   
    mygrid.getCombo(5).put(‘Low’,“Low”);
    mygrid.getCombo(5).put(‘Medium’,“Medium”);
    mygrid.getCombo(5).put(‘High’,“High”);
      mygrid.init();
    mygrid.loadXML(xmlFile);

And i have used php code for generating XML file for subgrid. There i am setting the header, coltypes and all other parameters.
so how do i create object for subgrid. Could you please help me.


Subgrid can be got by grid.cells(row_id,cell_index).getSubGrid() method. But subgrid is created when you open it.


You can should check if the subgrid exists:


function setState(){
state = document.getElementById(“ch”).checked?1:0;
mygrid.forEachRow(function(id){
var subgrid = mygrid.cells(id,0).getSubGrid();
if(subgrid)
subgrid.forEachRow(function(sid){
subgrid.cells(sid,INDEX).setValue(state);
});
});
}




i got the error is mygrid.cells(id, 0).getSubGrid is not a function
Is it need any new js file?


No, you don’t need any special js file. The sample in your package is dhtmlxGrid/samples/extended_modes/pro_subgrids.html


Please, check that cell type is sub_row_grid.

Hi, thanks for your help. I have included the necesary javascript files. But still it says that error 


mygrid.cells(id, 0).getSubGrid is not a function

Please help me.

Please be sure that all cells in the column “0” has type “sub_row_grid”, such error as in your case, can occur only if you are calling method against cell which doesn’t support it ( only sub_row_grid cell supports such method )

If you have mixed row values ( some rows have sub-grids and some are other types ) you can modify looping code as

mygrid.forEachRow(function(id){
var cell = mygrid.cells(id,0);
var subgrid = null;
if(cell.getSubGrid && (subgrid=cell.getSubGrid()))
subgrid.forEachRow(function(sid){
subgrid.cells(sid,INDEX).setValue(state);
});


Hi,
still dont have luck. It is not working for me. here i have attached my working files. i am developing the application using prado framework. It is a simple logic.i am using php file to generate grid xml and subgrid xml. Please have a look and suggest the changes.

Thanks

ViewManageEdit.page (3.47 KB)
ViewManageEdit.php.zip (1.87 KB)

Next is snippet from your code

function setState(){


state = document.getElementById(“ch”).checked?1:0;
mygrid.forEachRow(function(id)
{
var cell = mygrid.cells(id,0);
var subgrid = null;
if(cell.getSubGrid && (subgrid=cell.getSubGrid()))
subgrid.forEachRow(function(sid)
{
subgrid.cells(sid,INDEX).setValue(state);
});
});
}

The INDEX in
subgrid.cells(sid,INDEX).setValue(state);
need to be replaced with actual index of column for which checkbox state need to be changed

Working sample sent by email.

hi,
Thanks for your support. But i didn’t received any mail with attachment. login2vel@gmail.com is my alternate mail id. you can send that attachment to that email id.

Thanks,
Vel

Sample sent to login2vel@gmail.com