-1

I am using ExtJS 7.1 and created a grid panel. I am not able to retrieve the selected row using the code Ext.getCmp("tempGrid").getSelectionModel().getSelection(), this line of code always returns length of 0.

Ext.getCmp("tempGrid").getSelectionModel().hasSelection(), this line of code always return false.

I am not sure what went wrong, would like to seek for advise or suggestion. Thank you

I have a tab panel as a main panel (mainPanel) then I attached/linked another panel (called tempGrid) Inside the tempGrid, I will put the grid, here is the grid configuration

items: {
  xtype: 'gridpanel',
  id: 'tempGrid',
  header: false,
  forceFit: true,
  store: 'AStore',
  columns: [{
      xtype: 'gridcolumn',
      dataIndex: 'colA',
      text: 'A Column',
      filter: {
        type: 'string'
      }
    },
    {
      xtype: 'gridcolumn',
      dataIndex: 'colB',
      text: 'B Column',
      filter: {
        type: 'string'
      }
    }
  ],
  plugins: [{
    xtype: gridfilters ''
  }],
  dockedItems: [{
    xtype: 'pagingtoolbar',
    dock: 'bottom',
    displayInfo: true,
    inputItemWidth: 80,
    store: 'AStore'
  }]
}
Salman hassan
  • 398
  • 6
  • 23
xxestter
  • 441
  • 7
  • 19
  • The question may seem silly, but at the same time you have selected rows in your grid? – pvlt Mar 31 '20 at 10:58
  • Yes, I have selected one of the row in the grid then used Chrome Console to execute "Ext.getCmp("tempGrid").getSelectionModel().hasSelection()" and got false. I have also tried "Ext.getCmp("tempGrid").getSelectionModel().getSelection()", but got length 0 – xxestter Mar 31 '20 at 11:12
  • You could give an example of a grid configuration? – pvlt Mar 31 '20 at 11:14
  • Hi, I have copied my grid configuration into my question. Please advise. thank you so much – xxestter Apr 01 '20 at 06:52

3 Answers3

0

Your grid from your example of grid config has id APanel. You must call

Ext.getCmp("APanel").getSelectionModel().getSelection()

to get selected records. I think tempGrid is some another your grid

pvlt
  • 1,843
  • 1
  • 10
  • 19
  • Sorry, I made mistake while typing the code to StackOverFlow. I couldn't use copy and paste the code directly from Sencha Architect IDE to Stackoverflow for some reason. I have actually tried Ext.getCmp("tempGrid").getSelectionModel().getSelection(), but always give length 0 even though I have selected one record in the grid – xxestter Apr 02 '20 at 02:36
0

Your Function should be like this

var myGrid = this.getView();
var sl = myGrid.getSelectionModel().getSelection();
var items = new Array();
if (sl.length) {
  for (var i = 0; i < sl.length; i++) {
    items[i] = sl[i].get('recordId');
  }
}
return items;

And shouldn't be you xtype: 'grid' like this xtype: 'gridcolumn', please check that as well. Thanks

Hope This help

Salman hassan
  • 398
  • 6
  • 23
  • 1
    It is my typo for typing xtype: 'grid'on a gridcolumn. Sorry about it. I will try your suggestion and get back to you asap. Thank you. – xxestter Apr 02 '20 at 02:38
-1

i got solution to my problem hope it will help other to

var grid = Ext.getCmp('CenterGrid');
var selection= CenterGrid.getSelectionModel();

for(var i=0;i < grid.store.getCount();i++){
if(selection.isSelected(i)){
//these array assing to finalarray send to php below
c.push(
grid.store.getAt(i).data.Parameter_Name+ "||",
grid.store.getAt(i).data.Value + "||",
grid.store.getAt(i).data.Value2 + "||",
grid.store.getAt(i).data.Value3 + "||"

);
}
}
console.log("new:"+c);