David E
David E

Reputation: 23

Row Selection in Enhanced Grid

I am new to Dojo and i came across a problem that has me completely stumped. I am creating a data grid in Dojo with the Enhanced Grid .

Each row in the grid has a checkbox with which the row can be selected. The checkbox has been implemented using the indirectselection plugin.

Now when i select a row using the checkbox everything works fine. But when I select a row by clicking on other data cells the row does'nt get selected !

Heres the JSP part of the datagrid

<table  data-dojo-id="grid" data-dojo-type="dojox.grid.EnhancedGrid" plugins="{indirectSelection: {headerSelector:true}, filter: true,pagination: true}"
    data-dojo-props="store:icGrid, 
     clientSort:true "  formatterScope="myFormatters" 
    style="width: 100%; height: 20em;">
     <thead>
         <tr>
      <th width="25%" field="empNo"  formatter="formatLink">empNo</th>
      <th width="25%" field="name">name</th>
      <th width="25%" field="email">email</th>
      <th width="25%" field="phone">phone</th>
    </tr>
  </thead>
</table>

If I remove the code referring to indirect selection (plugins="{indirectselection...) the rows get selected when I click on other data cells (as they should). But I also need the checkbox that the indirectselection implements.

Is there a way to make the indirectselection work without taking away the row select functionality ?

Take a look at the grid in the page I will link below. I need a grid that works like that (The last grid in the page with the checkboxes)

http://dojotoolkit.org/documentation/tutorials/1.8/working_grid/demo/selector.php

Upvotes: 1

Views: 6600

Answers (5)

Hasnain Ali Bohra
Hasnain Ali Bohra

Reputation: 2180

The "SelectionChanged"` even is available. so code like this:-

grid.on("SelectionChanged", function(event)
    { 
        var rowId = event.rowIndex;
        grid.selection.setSelected(rowId, true);
        grid.render();
    }

Upvotes: 0

Hasnain Ali Bohra
Hasnain Ali Bohra

Reputation: 2180

Simple code :- "SelectionChanged"` even is available. so code like this:-

grid.on("SelectionChanged", function(event)
    { 
        var rowId = event.rowIndex;
        grid.selection.setSelected(rowId, true);
        grid.render();
          }

Upvotes: 0

David E
David E

Reputation: 23

I managed to resolve the issue by 1. using the cellClick event to listen 2. Get the rowindex of the cell when it is clicked 3. set it to selected.

grid.on("CellClick", function(event)
    { 
        var rowId = event.rowIndex;
        grid.selection.setSelected(rowId, true);
        grid.render();
          }

grid.selection.getSelected(); did not return the selected rows and I am wondering if this is a compatibility issue ? It seems like when i use the indirectSelection plugin the row Select is behaving in unexpected ways.

Upvotes: 1

user1445117
user1445117

Reputation: 199

Use this code below to listen to grid selection and check what selectedRows return and use the index of that row to toggleRow

dojo.connect(grid, "onRowClick", function(e) {
     var selectedRows= grid.selection.getSelected();
     grid.rowSelectCell.toggleRow(selectedRows[i], true);
});

Upvotes: 0

Yogeshkumar
Yogeshkumar

Reputation: 46

Have you ever heard about DGRID . I think you should check it. It really works very good with dojo .

Here are some useful sites .

Dgrid Main webpage

Git hub Documentation

Upvotes: 0

Related Questions