2011-06-23 80 views
0

我正在使用ExtJS4开发一些丰富的接口。我是ExtJS的初学者,我有一些问题。我有100条记录,我想每页显示20条记录。我已经完成了这个代码,但它只在所有页面显示20个记录。我已经在萤火虫中进行了验证,如果我掌握了所有数据:我只有20个,我的总数等于100.我需要帮助。工具栏Paging Extjs 4&Json问题

web服务页面:

[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页:

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()响应在萤火:

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”}

+0

您可以发布商店请求中的回复吗? – JamesHalsall

+0

坦克Jaitsu为您的回应,我刚刚在响应中添加商店响应 – Othman

+0

我只有20条记录,并且所有记录总数相等 – Othman

回答

0

当前您的回应是这样的......

{"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"}} 

但它应该是这样的......

{"_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"} 

而且你需要在你JsonStore更新您JsonReader配置..

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

问题是如果我只把“maListe”作为根记录不会显示在我的网格中,并且响应总是相同的:{“d”:{“_ type”:....} – Othman

+0

你有没有改变你的阅读器配置? 'reader'中的'root' config告诉Ext在 – JamesHalsall

+0

的哪里读取你的记录,如果我改变它,它不起作用,正确的根配置是:d.maListe – Othman

0

尽量保持老JSON响应和存储根属性(root:'d.maListe')并修改totalProperty:'总计'

+0

你好,我已经用Total和TotalProperty它不起作用:s – Othman

+0

如果我把总数属性我只有一个页面20个记录,但是当我把d.Total,我有20个记录和5页,但它是所有页面相同的记录 – Othman