PDA

View Full Version : How to use extraParams?



sencha.user
16 Nov 2012, 12:30 AM
Hi,

First I am sending a request (param) to the server and using the same PHP for another grid, but that grid doesn't give me data with passed param :-?, but when I send param in the url I can get it done. When I searched for it, there is an object extraParams, I am using like,


{
xtype: 'gridpanel',
url: 'php/update.php',
extraParams: {
'columnname': selectedField
}
}
This doesn't seem to work, it isn't sending the extra parameter. What am I doing wrong?

Thanks.

sencha.user
16 Nov 2012, 3:50 AM
I have to send parameter somewhere else, I did that and it worked. Now I have a CheckboxModel, I need to get value(s) of selected fields.

I have code like,

onCheckboxselectionmodelSelect: function(rowmodel, record, index, options) {
checkedField = record.get('Field');
}

checkedField has the currently selected value, how can I get array of selected values (comma separated, may be join() will do)?

Can someone help me? Thanks in advance.

Albareto
16 Nov 2012, 7:02 AM
grid.getSelectionModel().getSelection() (http://docs.sencha.com/ext-js/4-1/#!/api/Ext.selection.RowModel-method-getSelection)

That should return all the selected rows.

sencha.user
16 Nov 2012, 7:20 AM
Hi Albareto,

I have seen that as a solution in many threads, I am having my grid in Ext.apply(), how do i address 'grid' in grid.getSelectionModel().getSelection(), because it says 'undefined' 8-|. Please give me a simple code to get values and tell me how that is saved, like an array or we can have it comma separated (better for my requirement).

And also, I am getting JSON response from PHP, how do I save one of the values to a variable? Please help.

Thanks!

Albareto
16 Nov 2012, 7:27 AM
I cannot help you if you don't show your code. You can get components by using the Ext.ComponentQuery object or, in case your grid has an id, using Ext.getCmp('yourId');

For saving values that you receive after an update you can capture the load event from your store and put the logic you need there. But again without a sample code of how you are doing things it is difficult to answer your questions.

sencha.user
16 Nov 2012, 7:40 AM
Hi,

The grid looks like,


Ext.applyIf(me, {
items: [
{
xtype: 'gridpanel',
height: 223,
width: 133,
store: 'Store',
columns: [
{
xtype: 'gridcolumn',
width: 105,
dataIndex: 'Field',
text: 'Fields'
}
],
viewConfig: {
autoRender: true
},
selModel: Ext.create('Ext.selection.CheckboxModel', {
listeners: {
select: {
fn: me.onCheckboxselectionmodelSelect,
scope: me
}
}
})
}
]
});

me.callParent(arguments);
},

onCheckboxselectionmodelSelect: function(rowmodel, record, index, options) {
checkedField = record.get('Field');
}

So the checked values in this grid will be needed for another operation, for example, if the grid has,


test1
test2
test3
with checkboxes for it on left and if I am checking test1 and test2, I should have it like


variable = {test1, test2}
or something like this comma separated.

For JSON, if I am getting response like,


{"value":[{"Field":"test1","table":"tablename"},{"Field":"test2","table":"tablename"},{"Field":"test3","table":"tablename"}]

I want to save table to a variable, how that can be done?

Thanks in advance!

willigogs
16 Nov 2012, 8:23 AM
Where are you wanting to build the array of selected field values? You shouldn't do this on every checkbox select, but rather just prior to performing your AJAX call (I'm assuming on a button push somewhere?).



var selections = Ext.getCmp('your_grid_id').getSelectionModel().getSelection();
var arr = [];
Ext.each(selections, function(rec, index) {
arr.push(rec.get('Field'));
});


You can then pass "arr" as your extra param during the AJAX call.

sencha.user
17 Nov 2012, 12:55 AM
Hi willigogs,

Thanks for the reply. I did the one you told on a button and it works good, I check on checkboxes and while clicking button it sends like,


http://localhost/testing/php/update.php?fieldName=test1&fieldName=test2

Can I have these values like,

fieldName=test1, test2

I need to use this for another operation.

Please help in saving the JSON response to a variable I asked in my previous post.

Thanks!