开发者

problem with Toolbar Paging Extjs 4&Json

开发者 https://www.devze.com 2023-03-15 07:26 出处:网络
I\'m using ExtJS4 to develop some rich interfaces. I\'m a beginner with ExtJS and I i have some problems. I have 100 records and I want to show 20 records per page. I have done this code, but its only

I'm using ExtJS4 to develop some rich interfaces. I'm a beginner with ExtJS and I i have some problems. I have 100 records and I want to show 20 records per page. I have done this code, but its only showing 20 recording in all pages. I have verified in firebug if I have all my data: I have only 20 and my Total is equal to 100. I need help please.

Webservice page:

[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
[ScriptService]
public class Service : System.Web.Services.WebService
{
public class DataGridSource
    {
        public List<MyDvpt> maListe = new List<MyDvpt>();
        private int _total;
        public int Total 
        {
            get { return _total; }
            set {  _total = value; }
        }
    }

    [WebMethod]
    [ScriptMethod(ResponseFormat = ResponseFormat.Json, UseHttpGet = true, XmlSerializeString = false)]
    public DataGridSource GetMyDvpt3(int pageSize, int pageNumber)
    {
        string connectionString = "Data source=DARWIN;Initial Catalog=AGREO_DVPT;User ID=temp;Password=pmet";

        SqlConnection connection = new SqlConnection(connectionString);

        SqlCommand command = new SqlCommand("SELECT TOP 100 E.NOM_EXP,ESP.NOM_ESP,V.NOM_VAR,P.SURF_PG,P.DD_CYCLE_PROD from gc.PG P inner join ADM.EXP E on E.ID_EXP = P.ID_EXP inner join GC.VAR V on V.ID_VAR = P.ID_VAR inner join GC.ESP ESP on ESP.ID_ESP = V.ID_ESP", connection);

        connection.Open();

        SqlDataReader reader = command.ExecuteReader();

        List<MyDvpt> list1 = new List<MyDvpt>();
        while (reader.Read())
        {
            MyDvpt dev = new MyDvpt();
            dev.NOM_EXP = reader[0].ToString();
            dev.NOM_ESP = reader[1].ToString();
            dev.NOM_VAR = reader[2].ToString();
            dev.SURF_PG = reader[3].ToString();
            dev.DD_CYCLE_PROD = reader[4].ToString();

            list1.Add(dev);
        }
        return new DataGridSource { maListe = list1.Skip(pageSize * pageNumber).Take(pageSize).ToList<MyDvpt>(), Total = list1.Count };            
    }

public class MyDvpt
    {
        public string NOM_EXP { get; set; }
        public string NOM_ESP { get; set; }
        public string NOM_VAR { get; set; }
        public string SURF_PG { get; set; }
        public string DD_CYCLE_PROD { get; set; }

        private string _total;
        public string Total
        {
            get { return _total; }
            set { _total = value; }
        }
    }
}

JS page:

function onReady() {   
store = new Ext.data.JsonStore({
    autoLoad: true,
    pageSize: 20,
    pageNumber: 1,
    groupField: 'NOM_VAR',
    proxy: ({
        type: 'ajax',
        url: '../Service.asmx/GetMyDvpt3?pageSize=20 &pageNumber=1',
        reader: {
    开发者_开发问答        type: 'json',
            root: 'd.maListe',
            totalProperty: 'd.Total'            
        },
        headers: {
            'Content-type': 'application/json'
        }
    }),
    fields: ['NOM_EXP', 'NOM_ESP', 'NOM_VAR', 'SURF_PG', 'DD_CYCLE_PROD']
});


store.loadPage(1);

var groupingFeature = Ext.create('Ext.grid.feature.Grouping', {
    groupHeaderTpl: 'NOM_VAR: {NOM_ESP} ({rows.length} enregistrement{[values.rows.length > 1 ? "s" : ""]})'
});

Ext.create('Ext.grid.Panel', {
    store: store,
    id:'grid',
    collapsible: true,
    frame: true,
    iconCls: 'icon-grid',
    features: [groupingFeature],
    columnLines: true,
    columns: [
                { dataIndex: 'NOM_EXP', header: 'NOM_EXP', flex: 1 },
                { dataIndex: 'NOM_ESP', header: 'NOM_ESP', flex: 1 },
                { dataIndex: 'NOM_VAR', header: 'NOM_VAR', flex: 1 },
                { dataIndex: 'SURF_PG', header: 'SURF_PG', flex: 1 },
                { dataIndex: 'DD_CYCLE_PROD', header: 'DD_CYCLE_PROD', flex: 1 }
            ],

    fbar: ['->', {
        text: 'Clear Grouping',
        iconCls: 'icon-clear-group',
        handler: function () {
            groupingFeature.disable();
        }
    }],
    renderTo: 'panel',
    viewConfig: {
        stripeRows: true
    },
    title: 'Dvpt Grid',
    width: 1220,
    height: 500,
    dockedItems: [{
        xtype: 'pagingtoolbar',
        store: store,
        dock: 'bottom',
        displayInfo: true
    }]
});
}

store.load() response in firebug:

GET http://localhost:1508/Service.asmx/GetMyDvpt3?pa...22NOM_VAR%22%2C%22direction%22%3A%22ASC%22%7D%5D

{"d":{"_type":"MaquetteExtJs.Service+DataGridSource","maListe":[{"_type":"MaquetteExtJs.Service+MyDvpt","NOM_EXP":"DECKERT","NOM_ESP":"Blé Dur Hiver","NOM_VAR":"AMBRAL","SURF_PG":"30000","DD_CYCLE_PROD":"26/02/2003 00:00:00","Total":null}, ... {"__type":"MaquetteExtJs.Service+MyDvpt","NOM_EXP":"DECKERT","NOM_ESP":"Blé Dur Hiver","NOM_VAR":"SOLDUR","SURF_PG":"25000","DD_CYCLE_PROD":"06/03/2002 00:00:00","Total":null}],"Total":"100"}}

d Object { __type="MaquetteExtJs.Service+DataGridSource", maListe=[20], Total="100"}


Currently your response is like this...

{"d":{"_type":"MaquetteExtJs.Service+DataGridSource","maListe":[{"_type":"MaquetteExtJs.Service+MyDvpt","NOM_EXP":"DECKERT","NOM_ESP":"Blé Dur Hiver","NOM_VAR":"AMBRAL","SURF_PG":"30000","DD_CYCLE_PROD":"26/02/2003 00:00:00","Total":null}, ... {"__type":"MaquetteExtJs.Service+MyDvpt","NOM_EXP":"DECKERT","NOM_ESP":"Blé Dur Hiver","NOM_VAR":"SOLDUR","SURF_PG":"25000","DD_CYCLE_PROD":"06/03/2002 00:00:00","Total":null}],"Total":"100"}}

But it should be like this...

{"_type":"MaquetteExtJs.Service+DataGridSource","maListe":[{"_type":"MaquetteExtJs.Service+MyDvpt","NOM_EXP":"DECKERT","NOM_ESP":"Blé Dur Hiver","NOM_VAR":"AMBRAL","SURF_PG":"30000","DD_CYCLE_PROD":"26/02/2003 00:00:00","Total":null}, ... {"__type":"MaquetteExtJs.Service+MyDvpt","NOM_EXP":"DECKERT","NOM_ESP":"Blé Dur Hiver","NOM_VAR":"SOLDUR","SURF_PG":"25000","DD_CYCLE_PROD":"06/03/2002 00:00:00","Total":null}],"Total":"100"}

Also you need to update your JsonReader config in your JsonStore..

proxy: ({
    type: 'ajax',
    url: '../Service.asmx/GetMyDvpt3?pageSize=20 &pageNumber=1',
    reader: {
        type: 'json',
        root: 'maListe',
        totalProperty: 'Total'            
    }
}),


Try keeping old json response and store root property (root: 'd.maListe') and modify the totalProperty : 'Total'

0

精彩评论

暂无评论...
验证码 换一张
取 消