0

*I want to select similar records from grid1 and grid2 at the same time record is selected in grid1. *

For example say that if emp_id 1 has dept_id A and B and emp_id 2 has dept_id C,D and E. A user selects dept_id D . On the back automatically, emp_id 2 and dept_id C and E should get selected. If user selects emp_id 1 and 2 then on the back all the five dept_id should get selected.

Adding event handler for grid : 

{
 xtype : 'grid1',                                                           
 id:'accsearchgrid',
 cls:'accsearchgrid;                                                   
     listeners : {
                    select : function( thisobj, record, index, eOpts ){
                                 console.log("selected");
                                 var AccGridDetails = Ext.getCmp('accsearchgrid');//my grid1
                                 var GrpGridDetails = Ext.getCmp('grpsearchgrid');//my grid2
                                 var Accselection = AccGridDetails.getSelectionModel();
                                 var Grpselection = GrpGridDetails.getSelectionModel();
                                 var Accstore = Ext.getStore('AccDetailsStore');//grid1 store
                                 var Grpstore = Ext.getStore('GrpDetailsStore');//grid2 store
                                 items=[];
                                 for(i=0;i < Accstore.getCount();i++)
                                 {                  
                                    if(Accselection.isSelected(i))      
                                    {
                                       items.push({ 
                                          "prbalgrp"      : Accstore.getAt(i).data.prbalgrp //field which is same in both the grids.
                                        });
                                    }
                                 }
                                 var EncodeItems = Ext.encode(items);
                                 for(j=0; j < items.length ;j++)
                                 {
                                    for(i=0;i < Grpstore.getCount();i++)
                                    {
                                      console.log("items[j]pppp-->"+ items[j].prbalgrp);
                                      if(Grpstore.getAt(i).data.prbalgrp == items[j].prbalgrp){
                                          Ext.getCmp('grpsearchgrid').getSelectionModel().select(i); // error for first time  afterwards their is no problem but only one single record is seleted
                                      }
                                    }   
                                  }  
                                }   
                          }
            },

I am able to select only a single record in other grid. But I beginning error I am getting is :Uncaught TypeError: Cannot call method 'getAt' of undefined ext-all-debug.js:59297 Second time,I mean after selecting second record it is working fine. Please help resolve this.

Dev
  • 3,922
  • 3
  • 24
  • 44
  • What is your issue? getting the selections from the grid or selecting programmatically in the other grid or understanding the relations in your data model? – Amit Aviv May 07 '13 at 09:27
  • Selecting programmatically the records from both the grids simultaneously. – Dev May 07 '13 at 09:31
  • I mean to say that if a record is selected from grid 1 then related record (as i mentioned in above example) from grid 2 should be automatically selected at the back. – Dev May 07 '13 at 09:37
  • So, first, set an event handler that is activated when a selection occurs in one grid. In that handler retrieve the selected records from grid one, and find the matching records from grid two. Than select those records in grid two. Which of the stages is causing you problems? – Amit Aviv May 07 '13 at 09:44
  • Thanks Amit.I was facing problem like where to put the event handler.I w'll get back after trying what you have suggested. – Dev May 07 '13 at 09:51
  • I have edited adding event hadler select to my grid.I am getting error in beggining.it works fine thereafter with one problem that i am able to select only one record at a time.It should be possible for multiple records also.Can you please have a look.Thank you – Dev May 08 '13 at 10:42
  • which selection model are you using? selType & selModel properties of your grid – Amit Aviv May 08 '13 at 10:49
  • var selectionModel = new Ext.selection.CheckboxModel();selModel:selectionModel, – Dev May 08 '13 at 11:45

0 Answers0