ExtJs - проблемы с группировкой в ​​сетке - PullRequest
2 голосов
/ 30 сентября 2011

простая таблица содержит - id , name , text . Мне нужно занести эти данные в сетку с группировкой по полю name . Во всех найденных мною примерах (например - paper ) используется переменная, уже определившая данные. И мне нужно получить данные из Store .

ExtJs 3

код:

    Ext.onReady(function() {
    var store = new Ext.data.JsonStore({
        url           : 'get_from_db.php',
        storeId       : 'MyStore',
        totalProperty : 'totalCount',
        idProperty    : 'id',
        remoteSort    : true,
        fields : [ 
            {name : 'id',   type : 'int'},
            {name : 'name', type : 'String'},
            {name : 'text', type : 'String'}
        ]
    });
    store.load();

    var TestReader = new Ext.data.JsonReader({  
        idProperty : 'id',
        fields     : [
            {name : 'id',   type : 'int'},
            {name : 'name', type : 'String'},
            {name : 'text', type : 'String'}
        ]
    });


    var TestStore = new Ext.data.GroupingStore({
        reader    : TestReader,
        data      : 'get_from_db.php',
        sortInfo  : {
            field     : 'id',
            direction : 'ASC'
        },
        groupField : 'name'
    });


    var TaskGrid = new Ext.grid.GridPanel({
        store   : TestStore,
        columns : [
            {id : 'id',   header : 'Id',   dataIndex : 'id'},
            {id : 'name', header : 'Name', dataIndex : 'name'},
            {id : 'text', header : 'Text', dataIndex : 'text'}
        ],

        view    : new Ext.grid.GroupingView({
            forceFit     : true,
            groupTextTpl : '{text} ({[values.rs.length]} {[values.rs.length > 1 ? "Items" : "Item"]})'
        }),

        frame        : true,
        width        : 700,
        height       : 450,
        collapsible  : true,
        animCollapse : false,
        title        : 'Grouping',
        renderTo     : document.body
    });
});

В результате выводится сетка без единой ошибки, группа - но вот значения столбца - все нули

Ответы [ 2 ]

2 голосов
/ 03 октября 2011

решил .код:

Ext.onReady(function() {
var TestStore = new Ext.data.GroupingStore({
    url         : 'http://extjs/get_from_db.php',
    autoLoad    : true,

    remoteGroup : true,
    groupField  : 'name',

    sortInfo : {
        field     : 'id',
        direction : 'ASC'
    },

    reader : new Ext.data.JsonReader({
        totalProperty : 'totalCount',
        root          : 'items',
        idProperty    : 'id',

        fields: [
            {name : 'id',   type : 'int'},
            {name : 'name', type : 'String'},
            {name : 'text' ,type : 'String'}
        ]
    })
});

var TaskGrid = new Ext.grid.GridPanel({
    store    : TestStore,
    colModel : new Ext.grid.ColumnModel({
        columns : [
            {id     : 'id',   header    : 'Id', dataIndex : 'id'},
            {header : 'Name', dataIndex : 'name'},
            {header : 'Text', dataIndex : 'text'}
        ],
        defaults : {
            sortable     : true,
            menuDisabled : false,
            width        : 20
        }
    }),

    view : new Ext.grid.GroupingView({
        startCollapsed : true,
        forceFit     : true,
        groupTextTpl : '{text} ({[values.rs.length]} {[values.rs.length > 1 ? "Items" : "Item"]})'
    }),

    frame        : true,
    width        : 700,
    height       : 450,
    collapsible  : true,
    animCollapse : false,
    title        : 'Grouping',
    renderTo     : document.body
    });
});

Подробнее в этой заметке

2 голосов
/ 30 сентября 2011

отправьте код 'get_from_db.php', если можете, пожалуйста.

$ connect = mysql_connect ('localhost', 'root', ''); if ($ connect) mysql_select_db ('grid') или die ('ошибка с таблицей выбора'); $ select = mysql_query ("выберите * из теста"); while ($ rec = mysql_fetch_array ($ select)) $ columns [] = $ rec; echo json_encode ($ row);

Вы ошиблись, вернув JSON. Вместо

$ row [] = $ rec;

вам нужно

$ row [] = array ("id" => $ rec ['id'], "name" => $ rec ['name'], "text" => $ rec ['text']);

...