Am developing an application using GeoExt/OpenLayers and Geoeserver and am using more than ten (10) layers. I wanted to add a querying functionality on my application. I have done for one layer and is working really fine.


var secStore = Ext.create('GeoExt.data.FeatureStore', {
        layer: secschools,
        fields: [
            {name: 'Name_of_Sc', type: 'string'},
            {name: 'Girls_Boys', type: 'string'},
            {name: 'School_Spo', type: 'string'},
            {name: 'Day_or_Boa', type: 'string'},
    var sm = Ext.create('GeoExt.selection.FeatureModel', {
            autoPanMapOnSelection: true,
            mode: 'MULTI'
var secGrid = Ext.create('Ext.grid.GridPanel',{
        store: secStore,
        columns: [{header: "Name", flex:0.4, dataIndex: "Name_of_Sc"},
                {header: "Sponsor", flex:0.2, dataIndex: "School_Spo"},
                {header: "Girls/Boys", flex:0.2, dataIndex: "Girls_Boys"},
                {header: "Day/Boarding", flex:0.2, dataIndex: "Day_or_Boa"},
                xtype: 'textfield',
                margin: 2,
                enableKeyEvents: true,
                listeners: {
                    keyup: function() {
                        var store = this.up('grid').store;
                        if (this.value) {
                                property     : 'Name_of_Sc',
                                value         : this.value,
                                anyMatch      : true,
                                caseSensitive : false
                    buffer: 500
        stripeRows: true,
        selType: 'featuremodel',

The secschools is a WFS layer added on my map.As you can see the grid displays the records form the secschools layer and can be filtered using the textfield. The issue is, I will have to repeat this code as many times as the layers I want queried.

How can I handle such a querying functionality (to search e.g. 10 layers) in my app without doing as above?

1 Answer 1


You could use OpenLayers.Format.WFSDescribeFeatureType to make a DescribeFeatureType-Request and use the response to reconfigure your store and fill your grid.

Just have a look at the following GeoExt-Workshop (especially the "Bonus Task"-Section): http://workshops.boundlessgeo.com/geoext/wfs/grid.html

I won't post all the code from this workshop here as it's just too much an can be found on the workshop-website, but the following code-snippet will give you an idea how to get the information which fields have to be created for each layer :

var rawAttributeData;
var read = OpenLayers.Format.WFSDescribeFeatureType.prototype.read;
OpenLayers.Format.WFSDescribeFeatureType.prototype.read = function() {
    rawAttributeData = read.apply(this, arguments);
    return rawAttributeData;

If your store will be reconfigured for each active layer you can setup a more generic filter function in a next step.

  • Thank you Thomas for this.I had looked at the example but what I can't understand is how to do this for each layer.I have eight layers that I want do display their attributes once selected.
    – Wanjohi254
    Commented Mar 10, 2015 at 23:42
  • This is already done in the example. see this section: --- "When a layer is selected in the tree by clicking on its name, we want to issue a DescribeFeatureType request. This is done by appending the following code:" --- The selectionchange-event of the tree-selectionmodel is used to reconfigure the store and the grid.
    – Thomas B
    Commented Mar 11, 2015 at 10:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.