
Untitled
By: a guest on
Jul 29th, 2012 | syntax:
None | size: 4.37 KB | hits: 49 | expires: Never
ExtJS polling provider to poll rest call from server using store and grid
//Create store object to store json data from webservice call
var store = Ext.create('Ext.data.Store', {
autoLoad : true,
autoSync : true,
model : 'MuleJson',
proxy : {
type : 'rest',
url : '/list',
reader : {
type : 'json',
root : 'data'
},
writer : {
type : 'json'
}
},
listeners : {
write : function(store, operation) {
var record = operation.getRecords()[0], name = Ext.String
.capitalize(operation.action), verb;
if (name == 'Destroy') {
record = operation.records[0];
verb = 'Destroyed';
} else {
verb = name + 'd';
}
Ext.example.msg(name, Ext.String.format(
"{0} user: {1}", verb, record.getId()));
}
}
});
var rowEditing = Ext.create('Ext.grid.plugin.RowEditing');
//Create a grid panel to hold the store data
grid = Ext.create('Ext.grid.Panel', {
renderTo: 'notificationId',
plugins : [rowEditing],
width : 500,
height : 300,
frame : true,
title : 'Notifications',
tools : getTools(),
store : store,
iconCls : 'icon-notification',
columns : [{
text : 'ID',
width : 40,
sortable : true,
dataIndex : '_id'
}, {
text : 'Form 1',
flex : 1,
sortable : true,
dataIndex : 'form1name',
field : {
xtype : 'textfield'
}
}, {
header : 'Form 2',
width : 80,
sortable : true,
dataIndex : 'form2name',
field : {
xtype : 'textfield'
}
}, {
text : 'Form 3',
width : 80,
sortable : true,
dataIndex : 'form3name',
field : {
xtype : 'textfield'
}
}],
dockedItems : [{
xtype : 'toolbar',
items : [{
text : 'Add',
iconCls : 'icon-add',
handler : function() {
// empty record
store.insert(0, new MuleJson());
rowEditing.startEdit(0, 0);
}
}, '-', {
itemId : 'delete',
text : 'Delete',
iconCls : 'icon-delete',
disabled : true,
handler : function() {
var selection = grid.getView()
.getSelectionModel().getSelection()[0];
if (selection) {
store.remove(selection);
}
}
}]
}]
});
Ext.direct.Manager.addProvider(
{
type:'polling',
url: myTestFunction,
id: 'json poll',
interval: 5000
}
);
var pollB = Ext.direct.Manager.getProvider('json poll');