oria / gridx

Just another powerful Dojo grid
Other
162 stars 78 forks source link

Gridx RowHeader BUG! #238

Open toplinuxsir opened 10 years ago

toplinuxsir commented 10 years ago

when you enable RowHeader and set the Grid store to QueryReadStore, The console output as is below: TypeError {stack: "TypeError: Cannot read property 'setAttribute' of …dx/core/model/cache/Async.js?1403828718712:383:15", message: "Cannot read property 'setAttribute' of undefined"}

yurychika commented 10 years ago

Can you provide some sample code to reproduce this issue? Looks like it's not the bug of rowHeader.

toplinuxsir commented 10 years ago

The store class: /**

define([ "dojo/_base/declare", "dojo/_base/lang", "dojo/_base/array", "dojox/data/QueryReadStore" ], function (declare, lang, arrayUtil, QueryReadStore) { console.log("loading the AutoStore module");

return declare("zhai.store.AutoStore", QueryReadStore, {

    arrayAttr: 'rows',

    constructor: function (args) {
        declare.safeMixin(this, args);
        this.inherited(arguments);
    },

    fetch: function (request) {
        //console.log("fetch");
        //console.log(request.serverQuery);
        // add the serverQuery attribute to the AutoStore Object
        var self = this;
        if (self.serverQuery) {
            request.serverQuery = lang.mixin({}, self.serverQuery, request.serverQuery || {});
        }

        this.inherited('fetch', arguments);
    },

    _xhrFetchHandler: function (data, request, fetchHandler, errorHandler) {
        var self = this;
        //console.log(this._labelAttr);

        if (!data.items) {
            if (self.arrayAttr) {
                data.items = data[self.arrayAttr];

            } else {
                if (!data.rows) {
                    console.log("critical---error not specified the arrayAttr");
                }
                data.items = data.rows;
            }
        } else if (data.rows.length > 0) {
            data.items = data.rows;
            //console.log(data)
        }
        if (data.results) {
            data.numRows = data.results;
            if (data.results < data.items.length) {
                data.numRows = data.items.length;
            }

        }
        /*if (!data.identifier) {
         data.identifier = 'id';
         }*/
        if (self.identifier) {
            data.identifier = self.identifier;
        }
        if (data.items.length > 0 && self.searchAttr && self.labelAttr) {
            /**process when labelAttr != searchAttr */
            if (!data.items[0][this.searchAttr]) {
                arrayUtil.forEach(data.items, function (item) {
                    item[self.searchAttr] = item[self.labelAttr]
                });
            }
        }

        //console.log(data.numRows);
        this.inherited('_xhrFetchHandler', arguments)
        //console.log(request);
    }

});

});

The grid class: /**

define( [ 'dojo/_base/declare', 'dojo/_base/lang', 'dojo/aspect', 'gridx/modules/ColumnResizer', 'gridx/modules/RowHeader', 'gridx/modules/Focus', 'gridx/modules/IndirectSelect', 'gridx/modules/select/Row', 'gridx/modules/Dod', 'gridx/Grid' ], function (declare, lang, aspect, resizer, RowHeader, Focus, IndirectSelect, Row, Dod, Gridx) {

    var detailProvider = function (node, rowid) {
        console.log(this);
        console.log(rowid);
        console.log(node);
        console.log(this.model.byId(rowid));
    };

    return declare("zhai.ui.Grid", Gridx, {

        constructor: function (args) {
            /*
             * default to add ColumnResizer
             * i
             * **/
            var t = this;
            var dodModule = {
                moduleClass: Dod,
                defaultShow: false,
                useAnimation: true,
                showExpando: true,
                detailProvider: detailProvider
            };
            if (args.modules) {
                args.modules.push(resizer);
                args.modules.push(Focus);
                args.modules.push(RowHeader);
                // args.modules.push(IndirectSelect);
                args.modules.push(Row);

                //args.modules.push(dodModule);

            } else {
                args.modules = [resizer, Focus, Row,RowHeader] //dodModule];
            }
            declare.safeMixin(this, args);

            this.inherited(arguments);
            aspect.after(t, 'onModulesLoaded', function () {
                //if have paginationBar refresh to show correct information
                if (t.paginationBar) {
                    t.paginationBar.refresh();
                    //console.log('refresh the paginationBar');
                }
            });
        }

    });

}

);

toplinuxsir commented 10 years ago

/**

require([ "dojo/_base/kernel", "dojo/_base/lang", "dojo/_base/array", 'zhai/store/AutoStore', 'zhai/ui/AutoCompleteSelect', 'zhai/ui/Grid', 'gridx/modules/Pagination', 'gridx/modules/pagination/PaginationBar', 'gridx/modules/Dod', 'gridx/core/model/cache/Async', 'ready!' ], function (kernel, lang, arrayUtil, AutoStore, AutoCompleteSelect, Grid, Pagination, PaginationBar, Dod, Async) {

    console.log('html body is ready!');

    var select = new AutoCompleteSelect({
        url: '/qc/query_waste_form_no_bycode/',
        searchAttr: 'barcode',
        labelAttr: 'f_barcode',
        arrayAttr: 'rows',
        valueAttr: 'f_barcode',
        hasDownArrow: false,
        pageSize: 10
    }, "test_select");

    select.on('change', function (val) {
        console.log('changed val:' + val.toString());
        var _store = new AutoStore({
            url: '/qc/query_waste_form/',
            serverQuery: {barcode: val},
            identifier: 'i_id'
        });

        grid.setStore(_store);

    });

    /*var grid_store = new AutoStore({
     url: '/primary/query_prd_type/',
     requestMethod: 'get'
     });*/

    var grid_structre = [
        {name: '编号', field: 'i_barcode', width: '200px'},
        {name: '产品代码', field: 'prd_type_code', width: '90px'},
        {name: '批次', field: 'batch_str', width: '130px'},
        {name: '现象', field: 'appearance_name', width: '150px'},
        {name: '原因', field: 'reason_name', width: '150px'},
        {name: '发生工序', field: 'pos1_name', width: '150px'},
        {name: '发现工序', field: 'pos1_name', width: '150px'},
        {name: '责任部门', field: 'depart_name', width: '150px'},
        {name: '类别', field: 'ng_type_name', width: '100px'},
        {name: '处理方式', field: 'ng_action_name', width: '70px'},
        {name: '待判数量', field: 'count', width: '70px'},
        {name: '已判数量', field: 'scan_count', width: '70px'}

    ];

    var detailProvider = function (grid, rowid, node, rendered) {
        var t = grid;
        console.log(rowid);
        console.log(node);
        var item = t.model.byId(rowid);
        console.log(item);

        var detail_store = new AutoStore({
            url: '/qc/query_waste_item_scan_detail/',
            serverQuery: {id: item.item.i.i_id, start: 0, count: 1000, limit: 1000}
        });

        var detail_grid = new Grid({
            cacheClass: Async,
            store: detail_store,
            autoWidth: true,
            style: 'margin-left:30px; margin-right:30px; margin-top:20px; margin-bottom:20px;',
            structure: [
                {name: '条形码', field: 'barcode', width: '300px'},
                //{name: '现象', field: 'apperance', width: '170px'},
                {name: '判定人', field: 'checker', width: '170px'},
                {name: '判定扫描时间', field: 'scan_time', width: '300px'}

            ]

        });

        detail_grid.placeAt(node);
        rendered.callback();

    };

    var grid = new Grid({
        cacheClass: Async,
        //store: grid_store,
        //style: 'height:600px;',
        //rowHeaderWidth: '30px',
        //cacheSize: -1,
        //pageSize: 80,
        style: 'width:100%;height:100%',
        paginationPageSize: 3,
        paginationInitialPage: 0,
        //autoHeight: true,
        paginationInitialPageSize: 80,
        paginationBarSizeSwitch: false,
        paginationBarSizes: [80, 200],
        structure: grid_structre,
        paginationBarMessage: "${2} to ${3} of ${0} 项",
        modules: [
            Pagination,
            PaginationBar,
            {
                moduleClass: Dod,
                defaultShow: false,
                useAnimation: true,
                showExpando: true,
                detailProvider: detailProvider
            }
        ]

    }, 'test_grid');

    select.startup();
    grid.startup();
    console.log("startup the autoCompleteSelect");

}

);