Opened 10 years ago

Closed 10 years ago

#10323 closed defect (wontfix)

Dojox grid adds new item regardless of whether it matches query.

Reported by: alemik Owned by: Nathan Toone
Priority: high Milestone: 1.4
Component: DojoX Grid Version: 1.3.2
Keywords: dojox grid query Cc:
Blocked By: Blocking:

Description

Hi all,

I'm having a problem with dojox grid.

I have a following grid:

var myLayout = [
{
      name : this.dict[ "use" ],
      width : "auto",
      styles : "text-align: center",
      type : dojox.grid.cells.Bool,
      field: "selected",
      editable : !this.ro
},
{
    name : this.dict[ "form" ],
    field : "title",
    width : "175px"
},
{
    name : this.dict[ "description" ],
    field : "description",
    width : "325px"
},
{
    name : this.dict[ "instances" ],
    field : "tempInstanceCount",
    width : "70px"
    }
];

this.grid = new dojox.grid.DataGrid({
    id : "groupAdminGrid",
store : this.store,
query : { type : "form" },
queryOptions : { deep : true },
structure : myLayout,
style : "width : 650px; height : 300px;"
});

When I add new item to store, it appears in the grid as well, regardless of the "type" attribute. So for example I might end up with groups or image items in a list where I should have only forms.

this.store.newItem(
            {
                id : myId,
                type : "formreference",
                <some more attributes>
            },
            {
                parent : formgroupItem, 
                attribute : "children"
            });

Would it make sense to validate the query attribute when adding new item in the grid? For example make _onNew function to fetch all the items that match the query and then check for the keys? Eventually I just overrode the _onNew function in dojox.grid.DataGrid? with my own:

/**
  * Validates whether there is any matching key item to be added in query used or if it uses wildcard,
  * if true - add a new item.
  */
    _onNew : function(item, parentInfo)
    {
        for( var key in this.query )
        {
            if( this.query[key] == '*' ||
                this.query[key] == this.store.getValue( item, key ) )
            {
                var rowCount = this.attr('rowCount');
                this._addingItem = true;
                this.updateRowCount(rowCount+1);
                this._addingItem = false;
                this._addItem(item, rowCount);
                this.showMessage();
                break;
            }
        }
    }

I'm not sure though whether each item will have a store and query - they do in application I'm currently work on, so I've omitted the checks of whether those things exist or not.

Change History (1)

comment:1 Changed 10 years ago by Nathan Toone

Resolution: wontfix
Status: newclosed

This is the correct approach to take - but the data API doesn't have a mechanism to do this in a generic way. You will need to make this change in a store-specific way in your own application.

Note: See TracTickets for help on using tickets.