PDA

View Full Version : how to load data with ?select=field1,field2 options using rest



entropia
1 Sep 2011, 4:01 PM
Hello!..

There is model with many fields.


Ext.define('GksksAisk.model.Client', {
extend: 'Ext.data.Model',
idProperty: 'clientId',
fields: [
{ name: 'clientId', mapping: 'client_id', type: 'int', useNull: true, disabled: false, submitValue: false },
{ name: 'clientName', mapping: 'client_name', type: 'string' },
{ name: 'clientChairman', mapping: 'client_chairman', type: 'string' },
{ name: 'clientChiefAccountant', mapping: 'client_chief_accountant', type: 'string' },
{ name: 'clientContractNumber', mapping: 'client_contract_number', type: 'string' },
{ name: 'clientContractIndex', mapping: 'client_contract_index', type: 'string' },
{ name: 'clientContractDate', mapping: 'client_contract_date', type: 'date', dateFormat: 'Y-m-d'},
{ name: 'clientContact', mapping: 'client_contact', type: 'string' },
{ name: 'clientCommission', mapping: 'client_commission', type: 'float', useNull: true },
{ name: 'clientDebt', mapping: 'client_debt', type: 'float', useNull: true },
{ name: 'clientComments', mapping: 'client_comments', type: 'string' },
{ name: 'clientManager', mapping: 'client_manager', type: 'string' },
{ name: 'clientActive', mapping: 'client_active', type: 'bool' }
],


proxy: {
type: 'rest',
url: '/api/clients',
reader: {
type: 'json',
root: 'children',
successProperty: 'success'
},
writer: {
type: 'json',
writeAllFields: false
}
}
});




clientComments field may contain very big block of text so i try to avoid load this field if it is not used in my grid

I don't inderstand how to send request with ?select=client_id,client_name,client_active (or any another format) when store loads.

if i will just copy proxy to each store and change url to /api/clients?select=client_id,client_name,client_active - extjs will use this url with create, update and destroy requests, this not good...

skirtle
1 Sep 2011, 7:02 PM
Take a look at:

http://docs.sencha.com/ext-js/4-0/#!/api/Ext.data.proxy.Rest-method-buildRequest
http://docs.sencha.com/ext-js/4-0/source/Server.html#Ext-data-proxy-Server-method-buildRequest

You've got a choice of methods in there you could override to customize the parameters however you see fit.