PDA

View Full Version : MFS: Adding combobox column in RESTful Grid



fawad surosh
30 Jan 2011, 1:00 AM
I have setup a webform with RESTful Grid. my issue is that I can not fill a combobox from html file. can any one help me with filling combobox through html file. here i am copying you the js source code.

// Application instance for showing user-feedback messages.
var App = new Ext.App({});
// Create a standard HttpProxy instance.
var proxy = new Ext.data.HttpProxy({
url: 'app.php/users'
});
// Typical JsonReader. Notice additional meta-data params for defining the core attributes of your json-response
var reader = new Ext.data.JsonReader({
totalProperty: 'total',
successProperty: 'success',
idProperty: 'Id',
root: 'data',
messageProperty: 'message' // <-- New "messageProperty" meta-data
}, [
{name: 'Id'},
{name: 'Name', allowBlank: false},
{name: 'FatherName', allowBlank: false},
{name: 'Province', allowBlank: false}
]);
// The new DataWriter component.
var writer = new Ext.data.JsonWriter({
encode: false // <-- don't return encoded JSON -- causes Ext.Ajax#request to send data using jsonData config rather than HTTP params
});
// Typical Store collecting the Proxy, Reader and Writer together.
var store = new Ext.data.Store({
id: 'user',
restful: true, // <-- This Store is RESTful
proxy: proxy,
reader: reader,
writer: writer // <-- plug a DataWriter into the store just as you would a Reader
});
// load the store immeditately
store.load();
//
Ext.data.DataProxy.addListener('beforewrite', function(proxy, action) {
App.setAlert(App.STATUS_NOTICE, "Before " + action);
});
////
// all write events
//
Ext.data.DataProxy.addListener('write', function(proxy, action, result, res, rs) {
App.setAlert(true, action + ':' + res.message);
});
////
// all exception events
//
Ext.data.DataProxy.addListener('exception', function(proxy, type, action, options, res) {
App.setAlert(false, "Something bad happend while executing " + action);
});
// Let's pretend we rendered our grid-columns with meta-data from our ORM framework.
var userColumns = [
{header: "Id", width: 40, sortable: true, dataIndex: 'Id'},
{header: "Name", width: 100, sortable: true, dataIndex: 'Name', editor: new Ext.form.TextField({})},
{header: "FatherName", width: 50, sortable: true, dataIndex: 'FatherName', editor: new Ext.form.TextField({})},
{header: "Province", width: 50, sortable: true, dataIndex: 'Province', editor: new Ext.form.ComboBox({})}
]

Ext.onReady(function() {
Ext.QuickTips.init();
// use RowEditor for editing
var editor = new Ext.ux.grid.RowEditor({saveText: 'Update'});
// Create a typical GridPanel with RowEditor plugin
var userGrid = new Ext.grid.GridPanel({
renderTo: 'user-grid',
iconCls: 'icon-grid',
frame: true,
title: 'Users',
height: 300,
store: store,
plugins: [editor],
columns : userColumns,
tbar: [{
text: 'Add',
iconCls: 'silk-add',
handler: onAdd
}, '-', {
text: 'Delete',
iconCls: 'silk-delete',
handler: onDelete
}, '-'],
viewConfig: {
forceFit: true
}
});
/**
* onAdd
*/
function onAdd(btn, ev) {
var u = new userGrid.store.recordType({
Name: '',
FatherName: '',
Province: '--Select One--'
});
editor.stopEditing();
userGrid.store.insert(0, u);
editor.startEditing(0);
}
/**
* onDelete
*/
function onDelete() {
var rec = userGrid.getSelectionModel().getSelected();
if (!rec) {
return false;
}
userGrid.store.remove(rec);
}
});