EXTJS 3.4 - Grouping gridpanel based on GeoExt.data.WMSCapabilitiesStore - extjs

I am trying to implement grouping to the gridpanel using grouping store and grouping view.
Basically I want to modify the example given in this link;
http://api.geoext.org/1.1/examples/wms-capabilities.html
It is using Geoext web mapping library developed on extjs framework.Here GeoExt.data.WMSCapabilitiesStore is the store used for data from a url in XML.
Sample working xml can be viewed here:
url for xml
I am modifying the code to group the resulted records based on for example, 'name'.
Some how I am not able to properly configure the grouping store.
Here is my code sample:
var store;
Ext.onReady(function() {
// create a new WMS capabilities store
store = new GeoExt.data.WMSCapabilitiesStore({
url: "data.xml"
});
// load the store with records derived from the doc at the above url
store.load();
store.on('load',function(store,records,opts){
console.log(store.getRange());
}); //show the array data in firebug console
var reader = new Ext.data.ArrayReader({
fields: [{name: 'title'},
{name: 'name'},
{name: 'queryable'},
{name: 'abstract'}
]});
var grpstore = new Ext.data.GroupingStore({
data: store,
autoLoad: true,
reader: reader,
sortInfo:{field: 'title', direction: "ASC"},
groupField:'name'
});
//SP
// create a grid to display records from the store
var grid = new Ext.grid.GridPanel({
title: "WMS Capabilities",
store: grpstore,
columns: [
{header: "Title", dataIndex: "title", sortable: true},
{header: "Name", dataIndex: "name", sortable: true},
{header: "Queryable", dataIndex: "queryable", sortable: true, width: 70},
{id: "description", header: "Description", dataIndex: "abstract"}
],
view: new Ext.grid.GroupingView({
forceFit:true,
groupTextTpl: '{text} ({[values.rs.length]} {[values.rs.length > 1 ? "Items" : "Item"]})'
}),
frame:true,
width: 700,
height: 450,
collapsible: true,
animCollapse: false,
autoExpandColumn: "description",
listeners: {
rowdblclick: mapPreview
},
iconCls: 'icon-grid',
fbar : ['->', {
text:'Clear Grouping',
iconCls: 'icon-clear-group',
handler : function(){
store.clearGrouping();
}
}],
renderTo: "capgrid"
});
function mapPreview(grid, index) {
var record = grid.getStore().getAt(index);
var layer = record.getLayer().clone();
var win = new Ext.Window({
title: "Preview: " + record.get("title"),
width: 512,
height: 256,
layout: "fit",
items: [{
xtype: "gx_mappanel",
layers: [layer],
extent: record.get("llbbox")
}]
});
win.show();
}
});
I am getting the panel with group options in the columns but the grid is empty. I tried many options in the data input of grouping store, but could not make it work.
Is it good way to get the data from 'store' as array, and then read it again in grouping store? But I couldnt make it working.
store.getRange() is showing all the data in the firebug console, probably as an array. I tried it as per this post. How to then call this array as data in grouping store, if this is a good way of doing it.
Any lead on this would be very helpful
Thanks
Sajid

I was looking to do exactly the same thing. I found two things:
You can use the store.Each function to copy the data from the WMSCapabilitiesStore to the Grouping Store
This was the trouble - the loading of the store is asynchronous, so you have to use store.on to set up a callback function to populate the groupingStore once the WMSCapabilitiesStore is finished loading.
Here's the code:
store = new GeoExt.data.WMSCapabilitiesStore({
url: "data.xml"
});
store.load();
grpStore = new Ext.data.GroupingStore({
groupField: 'name',
sortInfo: {field: 'name', direction: 'ASC'},
groupOnSort: true
});
store.on('load', function(store, records, options)
{
store.each(function(eachItem) {
grpStore.add(eachItem);
});
});
var grid = new Ext.grid.GridPanel({
store: grpStore,
columns: [
{header: "Title", dataIndex: "title", sortable: true},
{header: "Name", dataIndex: "name", sortable: true},
{id: "description", header: "Description", dataIndex: "abstract"}
],
autoExpandColumn: "description",
height: 300,
width: 650,
view: new Ext.grid.GroupingView({
forcefit:true,
groupTextTpl: '{text} ({[values.rs.length]} {[values.rs.length > 1 ? "Items" : "Item"]})'
})
});

Related

extjs3.4: How to use store filter on a grid

I am using ExtJS3.4.
I want to filter the billingstore based on value selected by the user for billingName.
So, How do I pass the value selected to the store or grid? How do I achieve this?
Here is my code:
// Store for the grid panel - has billing grid data
this.billingStore = new Ext.data.JsonStore({
autoLoad: {params:{start: 0, limit: 2}},
filter: {billingName}
proxy: new Ext.data.HttpProxy({
url: '/ELCM/Client/getBillingList.do',
}),
root: 'data',
fields: ['billingName','billingAmount','usedData','duration'],
totalProperty:'totalRows'
});
var billingStore = this.billingStore;
//view billing
this.billingGrid = new Ext.grid.GridPanel({
title: 'View Billing',
store: that.billingStore,
columns:[
{header: "Amount",dataIndex: 'billingAmount'},
{header: "Data Used", dataIndex: 'usedData'},
{header: "Duration", dataIndex: 'duration'}
],
sm: new Ext.grid.RowSelectionModel({singleSelect: true}),
bbar: new Ext.PagingToolbar({
store: that.billingStore, // grid and PagingToolbar using same store
displayInfo: true,
pageSize: 2
}),
listeners: {
rowclick : function(grid, rowIndex, e){
console.log("row Index "+rowIndex);
}
}
});
var billingGrid = this.billingGrid;
Thanks
Depending on what you want to filter by a simple filter method on the store will achieve what your looking for.
billingGrid.getStore().filter([{
property: '',
id: '',
value:
}
]);
Look at http://docs.sencha.com/extjs/4.2.2/#!/api/Ext.data.Store-method-filter for further information.
Check out this code ,how does the filter in ExtJS work its required the property (i.e billingName for filtering as per your example) then 'value' on basis of which the filter happen this 2 are the mandatory options required for the filter function to work other optional config property which is exactMatch & caseSensitive which add the accuracy to the filter function.
Try out the below code
// Store for the grid panel - has billing grid data
this.billingStore = new Ext.data.JsonStore({
autoLoad: {params:{start: 0, limit: 2}},
filter: [{
property: 'billingName',
value: ''//Data source which need to be filter or based on value selected by the user for billingName
exactMatch: true,
caseSensitive: true
}],
proxy: new Ext.data.HttpProxy({
url: '/ELCM/Client/getBillingList.do',
}),
root: 'data',
fields: ['billingName','billingAmount','usedData','duration'],
totalProperty:'totalRows'
});
var billingStore = this.billingStore;
//view billing
this.billingGrid = new Ext.grid.GridPanel({
title: 'View Billing',
store: that.billingStore,
columns:[
{header: "Amount",dataIndex: 'billingAmount'},
{header: "Data Used", dataIndex: 'usedData'},
{header: "Duration", dataIndex: 'duration'}
],
sm: new Ext.grid.RowSelectionModel({singleSelect: true}),
bbar: new Ext.PagingToolbar({
store: that.billingStore, // grid and PagingToolbar using same store
displayInfo: true,
pageSize: 2
}),
listeners: {
rowclick : function(grid, rowIndex, e){
console.log("row Index "+rowIndex);
}
}
});
var billingGrid = this.billingGrid;

Insert in grid data from two store

Hello i am want output in grid data from two store (store:'book' and store:'price')
i am do this:
Ext.define('TPL.book', {
title: 'Price for Books',
store: 'Book',
header: false,
stripeRows: true,
constructor: function (config) {
this.initConfig(config);
this.callParent(arguments);
},
initComponent: function() {
this.columns = [
{header: 'Id', dataIndex: 'id', flex: 1, hidden: true},
{header: 'Name', dataIndex: 'name', width: 600, hidden: false},
{header: 'Price', dataIndex: '???', width: 100, hidden: false},
];
this.callParent(arguments);
}
});
I am want in column 'Price' output data from store 'Price' where id from store 'Book' equal id from store 'Price'
You would just do a store filter on your click event or load event. Good example here: How to filter a store with multiple values at once?
If you have it in two stores and need to combine it down to one store you could do a Ext.each(array, function(value) {}); and then just push the matched pairs into a new store. I would use the filters and give them filter IDs though and you could then remove filters pretty easily.

extjs paging not working

I am using extjs to create some rich interfaces but I am having difficulty adding paging to the code. can someone show me how to add paging correctly to this code
Ext.require([
'Ext.data.*',
'Ext.grid.*'
]);
Ext.onReady(function(){
Ext.define('Book',{
extend: 'Ext.data.Model',
fields: [
// set up the fields mapping into the xml doc
// The first needs mapping, the others are very basic
{name: 'Author', mapping: 'ItemAttributes > Author'},
'Title', 'Manufacturer', 'ProductGroup'
]
});
// create the Data Store
var store = Ext.create('Ext.data.Store', {
model: 'Book',
autoLoad: true,
proxy: {
// load using HTTP
type: 'ajax',
url: 'sheldon-2.xml',
// the return will be XML, so lets set up a reader
reader: {
type: 'xml',
// records will have an "Item" tag
record: 'Item',
idProperty: 'ASIN',
totalRecords: '#total'
}
}
});
// create the grid
var grid = Ext.create('Ext.grid.Panel', {
store: store,
columns: [
{text: "Author", flex: 1, dataIndex: 'Author', sortable: true},
{text: "Title", width: 180, dataIndex: 'Title', sortable: true},
{text: "Manufacturer", width: 115, dataIndex: 'Manufacturer', sortable: true},
{text: "Product Group", width: 100, dataIndex: 'ProductGroup', sortable: true}
],
renderTo:'example-grid-group-v3',
width: 540,
height: 200
});
});
You just need to add a paging toolbar to the bbar config of your gridpanel and hook it up to the same store your grid is using. See an example: http://dev.sencha.com/deploy/ext-4.0.7-gpl/examples/grid/paging.html
Something like:
bbar: Ext.create('Ext.toolbar.Paging', {
store: store,
displayInfo: true,
displayMsg: 'Displaying items {0} - {1} of {2}',
emptyMsg: "No items to display"
})

how to bind json for extjs grid

I have a simple data in mysql and want to populate that data in a ExtJS grid
My code
Ext.onReady(function() {
var proxy = new Ext.data.HttpProxy({
url: 'connectextjs.php'
});
var reader = new Ext.data.JsonReader([{
name: 'Employee_ID',
mapping: 'Employee_ID'
}, {
name: 'Department_ID'
}, {
name: 'Name'
}, {
name: 'Email'
}])
var store = new Ext.data.Store({
proxy: proxy,
reader: reader
});
store.load();
// create the grid
var grid = new Ext.grid.GridPanel({
store: store,
columns: [{
header: "Employee_ID",
width: 90,
dataIndex: 'Employee_ID',
sortable: true
}, {
header: "Department_ID",
width: 90,
dataIndex: 'Department_ID',
sortable: true
}, {
header: "Name",
width: 90,
dataIndex: 'Name',
sortable: true
}, {
header: "Email",
width: 200,
dataIndex: 'Email',
sortable: true
}],
renderTo: 'example-grid',
width: 540,
height: 200
});
});
My problem is I can't load the data on the grid. Please help me I am new to ExtJS.
connectextjs.php should return the json formated data with Employee_ID,Deaprtment_ID ,Name and Email init. Namming Convention should be followed strictly.
You can set the data of the grid by using this method.
First, assign an id to your grid, like this:
itemId : 'myGrid';
Get the JSON loaded from your JSON call, like this:
Ext.Ajax.request({
url : 'connectextjs.php',
params : {
yourParam : 'yourParameters'
},
// --> success simply means your action has no errors
success : function (conn, response, options, eOpts){
var jsonResults = Ext.JSON.decode(conn.responseText);
// --> Now that you have your JsonResults Its time to set it to your grid
me.getView().down('#myGrid').setStore(jsonResults);
}
});

Initializing GridPanel and ArrayStore with empty array does not work

When I initialize my ArrayStore with some data then I can insert new records and everything displays correctly. However, if I initialize the ArrayStore with an empty array then while the first record inserted works every subsequent insert overwrites the first record in the grid.
This seems a simple problem but I can't find a working way to initialize the grid as empty.
So what am I doing wrong?
Many thanks in advance!
var myData = [
// Initializing with the following element works.
//['Hyannis Connector',3456.9,'Hyannis Connector Bridle Path','Hyannis Connector/Baden Powell'],
// Initializing with this element works but leaves an empty row in the grid..
//[]
];
// create the data store
segmentStore = new Ext.data.ArrayStore({
fields: [
{name: 'trailName'},
{name: 'segmentLength', type: 'float'},
{name: 'startJunction'},
{name: 'endJunction'},
]
});
// manually load local data
segmentStore.loadData(myData);
// create the Grid
segmentGrid = new Ext.grid.GridPanel({
region: 'south',
store: segmentStore,
columns: [
{header: 'Trail Name', width: 140, sortable: true, dataIndex: 'trailName'},
{header: 'Segment Length', width: 75, sortable: true, dataIndex: 'segmentLength'},
{header: 'Start Junction', width: 75, sortable: true, dataIndex: 'startJunction'},
{header: 'End Junction', width: 75, sortable: true, dataIndex: 'endJunction'},
],
stripeRows: true,
height: 150,
width: 600,
title: 'Trail Segments in Route',
layout: 'fit'
});
var defaultData = {
trailName: segment.getTrailName(),
segmentLength: segment.getLength(),
startJunction: '',
endJunction: ''
};
var recId = 3;
var p = new segmentStore.recordType(defaultData, recId);
segmentStore.insert(0, p);
The answer was provided in the ExtJS Forum.
I needed to ensure the record id of the new records was different.

Resources