Start Building Professional
Web Apps Today


 
Categories Question details Back To List
Question  posted by ez on Jun 09, 2009 07:33
open dhtmlx forum
How to block some row from selecting in setSubGrid?

Hi!

I have a grid that gets a values from subGrid like this

+ Men
- John
- Adam
+ Women
- Ann
- Kati


I would like to block main nodes (Men,Women) form selecting, the best solution is to expand sub nodes on click instead of default selecting values to main grid.

Answer posted by Alex (support) on Jun 09, 2009 07:49

Hello,

you can use onRowSelect event handler to open sub grid when wen or women row is selected:

grid.attachEvent("onRowSelect",function(row_id,ind){
  if(row_id=="id_men"||row_id=="id_women")
  grid.cells(id,0).open();

  grid.clearSelection();
})
 

Answer posted by ez on Jun 09, 2009 11:24
This solution partly works - root values are not transferred to main grid, but subGrid closes on "Man/Woman" clicks.
Answer posted by Alex (support) on Jun 10, 2009 01:52

Sorry for the misleading information. There was an issue in the provided code snippet - the correct is grid.cells(row_id,0).open(); instead of  grid.cells(id,0).open();

This solution works perfectly locally. So, please contact us at support@dhtmlx.com, provide your ref. number and we'll send you the sample.

Answer posted by ez on Jun 10, 2009 02:25
I gets:

subgridPluto_1369763_.cells(rowID, 0).open is not a function

By subGrid structure is

grandparent <-this is not selectable

---child
<-this is selectable selectable
---parent <-this is not selectable
------child <-this is selectable selectable

Answer posted by ez on Jun 10, 2009 02:33
I manage to open row by:

subgrid<portlet:namespace/>.openItem(rowID);

But, after opening the subGrit gets closed, I would like to know how to prevent closing subGrid when not selectable row is clicked?
Answer posted by dhxSupport on Jun 10, 2009 04:05
You can use "onSubRowOpen" event, which fires , each time when sub-row opened|closed, and define any kind of rules 

mygrid.attachEvent("onSubRowOpen",function(row_id,state){
   if (!state&&row_id=="ID_OF_NOT_SELECTABLE_ROW"){
      mygrid.grid.cells(row_id,0).open();
   }
});


Answer posted by ez on Jun 10, 2009 05:01
Once again - I manage to open rows on click, my current problem is that subGrid closes on every row click, even when clicked row is not selectable.

I other words, I dont know how to prevent subGrid from closing on any click.
Answer posted by dhxSupport on Jun 10, 2009 05:23
After some grid's or subGrid's rows closing "onSubRowOpen" event occurs. You can catch that event and open necessary row again. There is no another way to block some row from closing/opening. You can try to use dhtmlxTreeGrid which has more extended parent-child functionality. Please see more information here http://www.dhtmlx.com/docs/products/dhtmlxTreeGrid/index.shtml
Answer posted by ez on Jun 10, 2009 05:46
In my example the subGrid is in fact treegrid
Answer posted by dhxSupport on Jun 10, 2009 09:21
In such case you can use following events:
mygrid.attachEvent("onRowSelect",function(row_id,cellIndex){
  if(row_id=="id_men"||row_id=="id_women"){
  mygrid.openItem(row_id);
  mygrid.clearSelection();
  }
  });
  mygrid.attachEvent("onOpenStart",function(id,state){
 if (state==1&&(row_id=="id_men"||row_id=="id_women")) return false;
  else return true;
  });


Answer posted by ez on Jun 12, 2009 04:07
I try this and:

1. selectable rows are clickable OK
2. not selectable rows are not transferred to main grid OK
3. when I click on non selectable row the subGrid are closed - and this is wrong because no selection has been made NOT OK
Answer posted by Alex (support) on Jun 12, 2009 10:11

Hello, 

The event handler that was recommended in the previous answer must solve the third issue - the subrows of locked rows don't close when you select locked (parent) row.

mygrid.attachEvent("onOpenStart",function(id,state){
 if (state==1&&(id=="id_men"||id=="id_women")) return false; /*if a row is open, it won't be closed*/
  else return true;
});

Do you use this approach ?