使dojox.data.datagrid中的列无法使用

时间:2013-01-17 13:48:51

标签: dojo dojox.grid.datagrid

我有一个列不能在我的dojox.data.datagrid中检索任何数据,但是我已经放置了一个自定义可点击标题。我想在此列上禁用排序,以便在我尝试单击标题时不显示三角形。

我是如何实现这一目标的?

编辑以显示我的代码:

dojo.require("dojox.grid.DataGrid"); //FindTask
dojo.require("dojo.data.ItemFileReadStore"); //FindTask
dojo.require("esri.tasks.find"); //FindTask

var findTask, findParams;
var grid, store;
var searchExtent;

function doFind() {

            //Show datagrid onclick of search button and resize the map div.
            dojo.style("map", {
                    "height": "87%"});
            esri.show(datagrid);
            searchExtent = new esri.geometry.Extent ({
            "xmin":-9196258.30121186,"ymin":3361222.57748752,"xmax":-9073959.055955742,"ymax":3442169.390441412,"spatialReference":{"wkid":102100}
            });

            map.setExtent(searchExtent);

    //Set the search text to the value in the box
    findParams.searchText = dojo.byId("parcel").value;
            grid.showMessage("Loading..."); //Shows the Loading Message until search results are returned.
    findTask.execute(findParams,showResults);
  }

  function showResults(results) {
    //This function works with an array of FindResult that the task returns
    map.graphics.clear();
    var symbol = new esri.symbol.SimpleFillSymbol(esri.symbol.SimpleFillSymbol.STYLE_SOLID, new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_SOLID, new dojo.Color([98,194,204]), 2), new dojo.Color([98,194,204,0.5]));


    //create array of attributes
    var items = dojo.map(results,function(result){
      var graphic = result.feature;
      graphic.setSymbol(symbol);
      map.graphics.add(graphic);
      return result.feature.attributes;
    }); 

    //Create data object to be used in store
    var data = {
      identifier: "Parcel Identification Number",  //This field needs to have unique values. USES THE ALIAS!!!
      label: "PARCELID", //Name field for display. Not pertinent to a grid but may be used elsewhere.
      items: items
    };

     //Create data store and bind to grid.
    store = new dojo.data.ItemFileReadStore({ data:data });
    var grid = dijit.byId('grid');
    grid.setStore(store);

    //Zoom back to the initial map extent
    map.setExtent(searchExtent);

  }

  //Zoom to the parcel when the user clicks a row
  function onRowClickHandler(evt){
    var clickedTaxLotId = grid.getItem(evt.rowIndex).PARCELID;
    var selectedTaxLot;

    dojo.forEach(map.graphics.graphics,function(graphic){
      if((graphic.attributes) && graphic.attributes.PARCELID === clickedTaxLotId){
        selectedTaxLot = graphic;
        return;
      }
    });
    var taxLotExtent = selectedTaxLot.geometry.getExtent();
    map.setExtent(taxLotExtent);
  }

HTML:

<!--Data Grid-->
                            <div id="datagrid" dojotype="dijit.layout.ContentPane" region="bottom" splitter="true" style="width:100%; height:125px;">
                                    <table data-dojo-type="dojox.grid.DataGrid" data-dojo-id="grid"  id="grid" data-dojo-props="rowsPerPage:'5', rowSelector:'20px'">
                                        <thead>
                                            <tr>
                                                <th field="Parcel Identification Number" width="10%">
                        Parcel ID
                                                </th>
                                                <th field="Assessing Neighbornood Code" width ="20%">
                        Neighborhood Code
                                                </th>
                                                <th field="Property Class Code" width="10%">
                        Property Class
                                                </th>
                                                <th field="Site Address" width="57%">
                        Address
                                                </th>
                                                <th field="" width="2%"> <div class="GridCloseIcon" title="Close Grid" onclick="closeGrid();"></div>
                                                </th>                   
                                            </tr>
                                        </thead>
                                    </table>
                            </div>

2 个答案:

答案 0 :(得分:2)

覆盖datagrid实例的canSort方法,并为给定的“col”参数返回true或false。请参阅DataGrid文档的this section中的“canSort”。

如果是第3列不应该使用类似的东西进行排序:

myGrid = new DataGrid({
    ....
    canSort: function(col) {
        return !(Math.abs(col) === 3);
    },
    ....
}, yourGridElemId);

在您的代码中,尝试以下内容:

dojo.addOnLoad(setupGrid);

function setupGrid() {
    var grid = dijit.byId('grid');
    grid.canSort = function(col) {
        return !(Math.abs(col) === 3);
    }
}

答案 1 :(得分:0)

在创建DataGrid对象时,如下设置'canSort:false'。

grid = new DataGrid({
                canSort: false,

            }, "gridId");
相关问题