User 5842
User 5842

Reputation: 3029

Pass extJs Grid Value to Store PHP Script

I currently have a simple extJS Grid which is pulling data from a server and presenting it to the viewer. I would like to grab the value of the selected row, and then pass it to another PHP script for processing in order to display the results in another grid.

var roleInformationStore = Ext.create('Ext.data.Store', {
  autoLoad: true,
  autoSync: true,
  model: 'RoleInformation',
  proxy: {
    type: 'ajax',
    url: 'data.php',
    reader: {
      type: 'array',
    },
    writer: {
      type: 'json'
 }
}
});

var roleInformationGrid = Ext.create('Ext.grid.Panel', {
  store: roleInformationStore,
  width: '100%',
  height: 200,
  title: 'Roles',
  columns: [
  {
    text: 'Name',
    flex: 1,
    width: 100,
    sortable: false,
    hideable: false,
    dataIndex: 'role'
 }
 ],
 listeners: {
   cellclick: function(view, td, cellIndex, record, tr, rowIndex, e, eOpts) {
     roleInformationStore.proxy.extraParams = record.get('role');
    //Ext.Msg.alert('Selected Record', 'Name: ' + record.get('role'));
   }
 }
});

Using the listener in the current grid, I am able to get the value and show it using the alert method. Any suggestions on how to accomplish this?

Thanks

Upvotes: 1

Views: 373

Answers (1)

Alexander
Alexander

Reputation: 20224

For this to work, extraParams has to be an object of key-value string pairs, because an URI has to be something like data.php?key1=value1&key2=value2.

Style-wise, Sencha advises to use getters and setters, whenever possible.

Together, you get:

var store = Ext.getStore("roleInformationStore");
store.getProxy().setExtraParam("myRoleParamKey",record.get('role'));
store.load();

In PHP, you would get the parameter then using

$role = $_GET['myRoleParamKey'];

You can of course substitute myRoleParamKey for any alphanumeric literal you want, but make sure you use the same key on both server and client side. ;-)

Docs: setExtraParam

Upvotes: 2

Related Questions