ExtJs中的GridPanel取每一行其中一个字段的值,急!!!!

时间:2021-03-29 15:01:43

DataTable dt = DbHelperSQL.ExcuteQuery(sql);
for (int i = 0; i < dt.Rows.Count; i++)
{
    string id=dt.Rows[i]["ID"].ToString();
}

 我的意思就是从GridPane中取第i行的ID值.Rows[i]["ID"] 

 for (var i = 0; i < bGrid.getStrore().getCount(); i++) {
string id=dt.Rows[i]["ID"].ToString();//这里的意思就是取bGrid的每行的ID字段的值,具体写法不知道
}

GridPanel中的第i行的ID字段怎么表示啊

麻烦各位帮忙!!!

4 个解决方案

#1



bGrid.getStrore().getAt(i).get('ID');

#2


引用 1 楼 orange_shuiguo 的回复:
JavaScript code?1bGrid.getStrore().getAt(i).get('ID');
说这种方法

#3


引用 2 楼 licip 的回复:
引用 1 楼 orange_shuiguo 的回复:
JavaScript code?1bGrid.getStrore().getAt(i).get('ID');说这种方法

是这种么?

 for (var i = 0; i < bGrid.getStrore().getCount(); i++) {

        /*切换列表 EXT*/
        var MLcm = new Ext.grid.ColumnModel([{
            header: "代码",
            sortable: true,
            width: 20,
            dataIndex: 'ID'
        }, {
            header: "名称",
            sortable: true,
            width: 20,
            dataIndex: 'comp'
        }, {
            header: "单位",
            sortable: true,
            width: 20,
            dataIndex: 'posi'
        }, {
            header: "规格",
            sortable: true,
            width: 20,
            dataIndex: 'Eg'
        }, {
            header: "材质",
            sortable: true,
            width: 20,
            dataIndex: 'photo'
        }, {
            header: "颜色",
            sortable: true,
            width: 20,
            dataIndex: 'HouxuanID'
        }, {
            header: "图片",
            sortable: true,
            width: 20,
            dataIndex: 'photo',
            renderer: function (v) {
                return "<input id='show' type=image src='photo' title='show' style='width:20px;height:20px'  onmousemove=\"Imgmousemove(this)\"  onmouseout=\"Imgmouseout()\"  />";
            }
        }]);
        MLStore = new Ext.data.Store({
            proxy: new Ext.data.HttpProxy({
                method: 'POST',
                url: '../../../Hou.mvc/GetHouxuan',
                data: {st:bGrid.getStrore().getAt(i).get('ID')}
            }),
            reader: new Ext.data.JsonReader({
                totalProperty: 'totalCount',
                root: 'root',
                id: 'ID',
                fields: [{
                    name: 'ID',
                    type: 'string'
                }, {
                    name: 'comp',
                    type: 'string'
                }, {
                    name: 'posi',
                    type: 'string'
                }, {
                    name: 'Eg',
                    type: 'string'
                }, {
                    name: 'photo',
                    type: 'string'
                }, {
                    name: 'HouxuanID',
                    type: 'string'
                }, {
                    name: 'photo',
                    type: 'string'
                }]
            })
        });
        bBbar = new Ext.PagingToolbar({
            store: MLStore,
            pageSize: pageSize,
            displayInfo: true,
            beforePageText: '第',
            afterPageText: '页- 共{0}页',
            displayMsg: '显示 {0} - {1}条 / 共{2}条',
            emptyMsg: "暂无数据"
        });

        qGrid = new Ext.grid.GridPanel({
            renderTo: 'tLiebiao',
            autoWidth: true,
            autoHeight: true,
            store: MLStore,
            autoScroll: true,
            cm: MLcm,
            stripeRows: true,
            loadMask: {
                msg: '正在加载数据,请稍侯……'
            },
            trackMouseOver: true,
            viewConfig: {
                forceFit: true,
                enableRowBody: true,
                showPreview: true,
                getRowClass: function (record, rowIndex, p, store) {
                    return 'x-grid3-row-collapsed';
                }
            },
            bbar: bBbar
        });
        MLStore.load({ params: { start: 0, limit: pageSize} });
        qGrid.hide();
        /*切换列表 EXT Grid  end*/




        bBbar = new Ext.PagingToolbar({
            store: MLStore,
            pageSize: pageSize,
            displayInfo: true,
            beforePageText: '第',
            afterPageText: '页- 共{0}页',
            displayMsg: '显示 {0} - {1}条 / 共{2}条',
            emptyMsg: "暂无数据"
        });


        var xd = Ext.data;
        var tpl = new Ext.XTemplate(
'<tpl for="." >',
            '<div class="thumb-wrap" id="{ID}">',
    '<div class="thumb"><img WIDTH=165px  HEIGHT=140px src="{photo}" title="{ID}"></div>',
    '<span class="x-editable">{shortName}</span></div>',
        '</tpl>',
        '<div class="x-clear"></div>'
);

        panel = new Ext.Panel({
            id: 'images-view',
            frame: true,
            autoWidth: true,
            autoHeight: true,
            collapsible: true,
            layout: 'fit',
            title: '图片列表',

            items: new Ext.DataView({
                store: MLStore,
                tpl: tpl,
                autoHeight: true,
                multiSelect: true,
                overClass: 'x-view-over',
                itemSelector: 'div.thumb-wrap',
                emptyText: '无数据',
                prepareData: function (data) {
                    data.shortName = Ext.util.Format.ellipsis(data.C_name + data.E_name, 30);
                    return data;
                },
                listeners: {
                    'click': function (dataview, index, node, e) {
                        var record = dataview.getStore().getAt(index);
                        wOutWin(record.get('ID'));
                        //do sth...  
                    },
                    scope: this
                }

            }),
            bbar: bBbar

        });
        panel.render(document.body);
    }

做循环的时候总是报错:对象不支持此属性或方法!不知道怎么回事

#4


引用 1 楼 orange_shuiguo 的回复:

bGrid.getStrore().getAt(i).get('ID');

应该是getStore()

#1



bGrid.getStrore().getAt(i).get('ID');

#2


引用 1 楼 orange_shuiguo 的回复:
JavaScript code?1bGrid.getStrore().getAt(i).get('ID');
说这种方法

#3


引用 2 楼 licip 的回复:
引用 1 楼 orange_shuiguo 的回复:
JavaScript code?1bGrid.getStrore().getAt(i).get('ID');说这种方法

是这种么?

 for (var i = 0; i < bGrid.getStrore().getCount(); i++) {

        /*切换列表 EXT*/
        var MLcm = new Ext.grid.ColumnModel([{
            header: "代码",
            sortable: true,
            width: 20,
            dataIndex: 'ID'
        }, {
            header: "名称",
            sortable: true,
            width: 20,
            dataIndex: 'comp'
        }, {
            header: "单位",
            sortable: true,
            width: 20,
            dataIndex: 'posi'
        }, {
            header: "规格",
            sortable: true,
            width: 20,
            dataIndex: 'Eg'
        }, {
            header: "材质",
            sortable: true,
            width: 20,
            dataIndex: 'photo'
        }, {
            header: "颜色",
            sortable: true,
            width: 20,
            dataIndex: 'HouxuanID'
        }, {
            header: "图片",
            sortable: true,
            width: 20,
            dataIndex: 'photo',
            renderer: function (v) {
                return "<input id='show' type=image src='photo' title='show' style='width:20px;height:20px'  onmousemove=\"Imgmousemove(this)\"  onmouseout=\"Imgmouseout()\"  />";
            }
        }]);
        MLStore = new Ext.data.Store({
            proxy: new Ext.data.HttpProxy({
                method: 'POST',
                url: '../../../Hou.mvc/GetHouxuan',
                data: {st:bGrid.getStrore().getAt(i).get('ID')}
            }),
            reader: new Ext.data.JsonReader({
                totalProperty: 'totalCount',
                root: 'root',
                id: 'ID',
                fields: [{
                    name: 'ID',
                    type: 'string'
                }, {
                    name: 'comp',
                    type: 'string'
                }, {
                    name: 'posi',
                    type: 'string'
                }, {
                    name: 'Eg',
                    type: 'string'
                }, {
                    name: 'photo',
                    type: 'string'
                }, {
                    name: 'HouxuanID',
                    type: 'string'
                }, {
                    name: 'photo',
                    type: 'string'
                }]
            })
        });
        bBbar = new Ext.PagingToolbar({
            store: MLStore,
            pageSize: pageSize,
            displayInfo: true,
            beforePageText: '第',
            afterPageText: '页- 共{0}页',
            displayMsg: '显示 {0} - {1}条 / 共{2}条',
            emptyMsg: "暂无数据"
        });

        qGrid = new Ext.grid.GridPanel({
            renderTo: 'tLiebiao',
            autoWidth: true,
            autoHeight: true,
            store: MLStore,
            autoScroll: true,
            cm: MLcm,
            stripeRows: true,
            loadMask: {
                msg: '正在加载数据,请稍侯……'
            },
            trackMouseOver: true,
            viewConfig: {
                forceFit: true,
                enableRowBody: true,
                showPreview: true,
                getRowClass: function (record, rowIndex, p, store) {
                    return 'x-grid3-row-collapsed';
                }
            },
            bbar: bBbar
        });
        MLStore.load({ params: { start: 0, limit: pageSize} });
        qGrid.hide();
        /*切换列表 EXT Grid  end*/




        bBbar = new Ext.PagingToolbar({
            store: MLStore,
            pageSize: pageSize,
            displayInfo: true,
            beforePageText: '第',
            afterPageText: '页- 共{0}页',
            displayMsg: '显示 {0} - {1}条 / 共{2}条',
            emptyMsg: "暂无数据"
        });


        var xd = Ext.data;
        var tpl = new Ext.XTemplate(
'<tpl for="." >',
            '<div class="thumb-wrap" id="{ID}">',
    '<div class="thumb"><img WIDTH=165px  HEIGHT=140px src="{photo}" title="{ID}"></div>',
    '<span class="x-editable">{shortName}</span></div>',
        '</tpl>',
        '<div class="x-clear"></div>'
);

        panel = new Ext.Panel({
            id: 'images-view',
            frame: true,
            autoWidth: true,
            autoHeight: true,
            collapsible: true,
            layout: 'fit',
            title: '图片列表',

            items: new Ext.DataView({
                store: MLStore,
                tpl: tpl,
                autoHeight: true,
                multiSelect: true,
                overClass: 'x-view-over',
                itemSelector: 'div.thumb-wrap',
                emptyText: '无数据',
                prepareData: function (data) {
                    data.shortName = Ext.util.Format.ellipsis(data.C_name + data.E_name, 30);
                    return data;
                },
                listeners: {
                    'click': function (dataview, index, node, e) {
                        var record = dataview.getStore().getAt(index);
                        wOutWin(record.get('ID'));
                        //do sth...  
                    },
                    scope: this
                }

            }),
            bbar: bBbar

        });
        panel.render(document.body);
    }

做循环的时候总是报错:对象不支持此属性或方法!不知道怎么回事

#4


引用 1 楼 orange_shuiguo 的回复:

bGrid.getStrore().getAt(i).get('ID');

应该是getStore()