I have scenario in which I have to select features drawing a polygon and and get the attribute values in to a tables or lists.The features on the map consist of polygon, line,point at the same time so when he selects the features according to layer name I have to bind to separate tables.Is there any example tackling this scenario.

2 Answers 2


Adapted from some code I have -- untested here -- the key is using the dojo DeferredList so that you know when all the queries to the seperate layers have returned.

When building the table I would reccomend the DataTables jquery based library -- works well for me, lots of features. http://www.datatables.net/

function selectFeaturesFromPolygon() {
    drawToolbarDrawEndEvent = dojo.connect(drawToolbar, 'onDrawEnd', function (geom) {
        var aDeferreds = [],
            query = new esri.tasks.Query();

        query.geometry = geom;
        query.returnGeometry = true;
        query.outFields = ["*"];

        if (geom) {
            queryTask = new esri.tasks.QueryTask(FeatureServiceName1);
            //push multiple queries into this array

            queryTask = new esri.tasks.QueryTask(FeatureServiceName2);
            //push multiple queries into this array

            queryTask = new esri.tasks.QueryTask(FeatureServiceName3);
            //push multiple queries into this array

            // create a deferred list to aggregate the state for all identify queries
            deferredList = new dojo.DeferredList(aDeferreds);
            deferredList.then(function (aQueryResults) {
                //returns when all queries have finished
                //"aQueryResults" is 2D array of results
                //array[n][0] boolean true or false, success or failure of individual call
                //array[n][1] is the array of identity results returned
            }, function (err) {
                console.log("Error Occurred: " + err);

//datatable usage would be like this -- this is just a sample, you need to parse aQueryResults
//and put the values into cols, rows and data
//add some html somewhere <table id="tableSearchResults" cellpadding="0" cellspacing="0" border="0"   style="color: black;"></table>
function buildTableFromMultipleResults(aQueryResults) {

    var cols = [],
        row = [],
        data = [];

    //create columns
    $.each(results.fields, function (index, value) {
        cols.push({ 'sTitle': value.name });

    //create rows and push into data
    $.each(results.features, function (index, value) {
        row = [];
        $.each(value.attributes, function (index2, value2) {

    oTable = $('#tableSearchResults').dataTable({
        "aaData": data,
        "aoColumns": cols,
        "aoColumnDefs": [{ "bSortable": false, "aTargets": [0, 1] },
        { "bSearchable": false, "aTargets": [0, 1] },
        { "bVisible": false, "aTargets": currentSearchResults.hiddenFields },
        { "fnRender": function (o, val) {
            if (val !== null) {
                return Math.round(val * 1000) / 1000;
            else {
                return "";
        }, "aTargets": currentSearchResults.rounded
        "aaSorting": [[5, 'asc']],
        "iDisplayLength": 25,
        "aLengthMenu": [[10, 25, 50, 100, -1], [10, 25, 50, 100, "All"]],
        "bDestroy": true,
        "sDom": 'liT<"clear">tp'    

I don't think there is one sample doing what you need, but you should have a look at these two samples:

You will see in the second sample, that we need to pass a geometry to the query task. In your case, the geometry will come from the user drawn geometry.

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.