Gelmiş geçmiş en büyük porno sitemiz olan 2pe de her zaman en kaliteli pornoları sunmayı hedefledik. Diğer video sitemiz olan vuam da ise hd porno ağırlıklı çalışmalara başladık.

  1. #1
    Sencha User
    Join Date
    Nov 2011
    Location
    India
    Posts
    83
    Answers
    1
    Vote Rating
    0
    Rajat Sharma is on a distinguished road

      0  

    Default Answered: Changes required at Server side JSON for using Paging.

    Answered: Changes required at Server side JSON for using Paging.


    Hi
    I am an Ext begginner. I have a simple grid which (after it's fair share of problems) is able to fetch data from server that sends a JSONArray.
    Here are the code snippets:

    Server Side: JSONArray Generation
    Code:
    public JSONArray getUserJSON(){
    	    JSONArray userJSON = new JSONArray();
    	    String[] userArray = getuserArray();  //s java String array that contains the user list
    	    for(String val : userArray) {
    	        JSONObject user = new JSONObject();
    	        user.put("name", val);
    	        userJSON.add(user);
    	    }
    	    return userJSON;
    	}
    Client Side: Grid
    Code:
    var userStore = Ext.create('Ext.data.Store', {
            model: 'User',       
            proxy: {
            	type: 'ajax',
            	url : 'ActionServlet?task=userList',
            	reader: {
                	type: 'json',
                	model: 'User'
            	}
        	}
        });
    
    
        	Ext.create('Ext.grid.Panel', {
            	renderTo: Ext.getBody(),
            	store: userStore,
            	width: 400,
            	height: 800,
            	title: 'Users',
            	columns: [
                	{
                    	text: 'Name',
                    	width: 100,
                    	sortable: true,
                    	hideable: false,
                    	dataIndex: 'name'
                	}
            	],
            	dockedItems: [{
            	xtype: 'pagingtoolbar',
            	store: userStore,   // same store GridPanel is using
            	dock: 'bottom',
            	displayInfo: true
        	}]
        });
    	//userStore.load();
        userStore.load({
       		params: {
            	// specify params for the first page load if using paging
            	start: 0,
            	limit: 10
       	 	}
    		});
    	};
    I have managed this code from Ext PagingToolbar example. Infact "dockeditem" and adding parameters in "store.load" are the only two changes i have done.
    My grid is able to load data. But all 75 records come at once. When i click the "forward arrow button" from the paging toolbar, on page 2 also, the entire grid gets loaded again. Basically, i am not able to use paging.
    Now, http://docs.sencha.com/ext-js/4-0/#!...toolbar.Paging clearly says that
    Paging is typically handled on the server side. The client sends parameters to the server side, which the server needs to interpret and then respond with the appropriate data.
    Can someone please help on:
    1) is the problem with the server side format of the array? The current format of the array (verified using developer tools) is
    Code:
    [{"name":"glsextusr23"},{"name":"GLSEXTUSR36"},{"name":"XBBJVC0"},{"name":"XBBKBJC"}..........and son on...]
    2) if yes, how to recode and what is the concept behind this. The format specifed at the Ext API site is

    {"success":true,"results":2000,"rows":[// ***Note:** this must be an Array{"id":1,"name":"Bill","occupation":"Gardener"},{"id":2,"name":"Ben","occupation":"Horticulturalist"},...{"id":25,"name":"Sue","occupation":"Botanist"}]}Do these two values i.e success and results, pertain to paging. My JSON sent is an Array where as the example shows an Object (which has an Array). Do I need to change mine ? Please guide.
    Thanks

  2. The store will send a request a little like this:

    Code:
    ActionServlet?task=userList&page=1&start=0&limit=10&...
    Your server must read and interpret these parameters. limit gives the page size and start gives the index of the first result. The parameter page gives the page number. Obviously you don't need all 3 to work out which page to return, you should choose which combination of these parameters make most sense for you.

    Responsibility for returning the correct results lies solely with the server. If 10 results are requested you must return no more than 10 results. If you return 100 results they will still be added to the store and appear in the grid. The store will not attempt to perform internal paging if you return too many results.

    Let's consider a JSON response like this:

    Code:
    {
        "count": 78,
        "data": [
            {"name": "Tom"},
            ...
        ]
    }
    Here the data array should contain 10 results. The value count specifies the total number of results. In this case that tells the store that there are 8 pages. To configure a reader to consume this data you would need:

    Code:
    {
        ...
        root: 'data',
        totalProperty: 'count'
    }
    Note that you can save yourself a bit of config if you call your total property total as that is the default.

    As you have already mentioned, simply returning an array as your response cannot work as there is no way to pass the total number of results to the store.

  3. #2
    Ext JS Premium Member tvanzoelen's Avatar
    Join Date
    Apr 2008
    Location
    Groningen - Netherlands
    Posts
    1,111
    Answers
    83
    Vote Rating
    30
    tvanzoelen has a spectacular aura about tvanzoelen has a spectacular aura about tvanzoelen has a spectacular aura about

      0  

    Default


    Yes you must define a total property on your reader and set your data under a root

    Code:
    reader: {
        type : 'json',
        root : 'data', //or the property where your data is in the returned JSON
        totalProperty  : 'total', //mapping to the property where the total number of record is found
        successProperty: 'success'
    }
    Only return the records from the server wich are requested within the start and limit params.

  4. #3
    Sencha User
    Join Date
    Nov 2011
    Location
    India
    Posts
    83
    Answers
    1
    Vote Rating
    0
    Rajat Sharma is on a distinguished road

      0  

    Default


    tvanzoelen

    Thanks for attending to question once again.
    The current code for reader works normally. Of course, this may be incomplete in certain ways.
    Code:
    reader: {
                	type: 'json',
                	model: 'User'
            	}
    According to the API, totalProperty is Name of the property from which to retrieve the total number of records in the dataset. I have explicitly set it to 'total' but no use. Can you please elaborate on it's purpose. I also do not understand root property clearly.
    This is the new reader after making suggested changes:
    Code:
    reader: {
                	type: 'json',
                	model: 'User',
                	totalProperty  : 'total',
                	successProperty: 'success',
    // is 'name' correct value for root property ? format of JSON is posted above
                	root: 'name'
            	}
    However, no changes despite this in output. Complete grid loading on every page.

  5. #4
    Sencha User
    Join Date
    Nov 2011
    Location
    India
    Posts
    83
    Answers
    1
    Vote Rating
    0
    Rajat Sharma is on a distinguished road

      0  

    Default


    Only return the records from the server wich are requested within the start and limit params.
    Do you mean I have to manually return only a given number of records from server. For example,
    Code:
    userStore.load({
               params: {
                // specify params for the first page load if using paging
                start: 0,
                limit: 10
                }
            });
    So it is our task to make sure that only 10 records are returned at a time. All the sequencing of records at server side has to be taken care off. Do I understand you correctly ?

  6. #5
    Ext JS Premium Member tvanzoelen's Avatar
    Join Date
    Apr 2008
    Location
    Groningen - Netherlands
    Posts
    1,111
    Answers
    83
    Vote Rating
    30
    tvanzoelen has a spectacular aura about tvanzoelen has a spectacular aura about tvanzoelen has a spectacular aura about

      0  

    Default


    You must define totalproperty and your root in the reader

    Code:
    {success: true,  total: 75, data: [{"name":"glsextusr23"},{"name":"GLSEXTUSR36"},{"name":"XBBJVC0"},{"name":"XBBKBJC"}..........and son on...]}
    Your data section must return that many records as the size your pagesize. Do not return 75 records at once but eg. 10 if your pagesize is ten.

  7. #6
    Ext JS Premium Member tvanzoelen's Avatar
    Join Date
    Apr 2008
    Location
    Groningen - Netherlands
    Posts
    1,111
    Answers
    83
    Vote Rating
    30
    tvanzoelen has a spectacular aura about tvanzoelen has a spectacular aura about tvanzoelen has a spectacular aura about

      0  

    Default


    yes

  8. #7
    Sencha User
    Join Date
    Nov 2011
    Location
    India
    Posts
    83
    Answers
    1
    Vote Rating
    0
    Rajat Sharma is on a distinguished road

      0  

    Default


    I am clear about the second part. I will send only <pageSize> number of records.
    However, regarding the JSON change at server side. Current format is a JSONArray:
    Code:
    [{"name":"glsextusr23"},{"name":"GLSEXTUSR36"},{"name":"XBBJVC0"},{"name":"XBBKBJC"}...]
    The format suggested by you seems to be a JSONObject where the value of the 'data' property is my JSONArray. So I got to change the design, and return JSONObject instead of JSONArray. Hope I have got you correctly.

  9. #8
    Sencha Premium Member skirtle's Avatar
    Join Date
    Oct 2010
    Location
    UK
    Posts
    3,475
    Answers
    523
    Vote Rating
    280
    skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future

      0  

    Default


    The store will send a request a little like this:

    Code:
    ActionServlet?task=userList&page=1&start=0&limit=10&...
    Your server must read and interpret these parameters. limit gives the page size and start gives the index of the first result. The parameter page gives the page number. Obviously you don't need all 3 to work out which page to return, you should choose which combination of these parameters make most sense for you.

    Responsibility for returning the correct results lies solely with the server. If 10 results are requested you must return no more than 10 results. If you return 100 results they will still be added to the store and appear in the grid. The store will not attempt to perform internal paging if you return too many results.

    Let's consider a JSON response like this:

    Code:
    {
        "count": 78,
        "data": [
            {"name": "Tom"},
            ...
        ]
    }
    Here the data array should contain 10 results. The value count specifies the total number of results. In this case that tells the store that there are 8 pages. To configure a reader to consume this data you would need:

    Code:
    {
        ...
        root: 'data',
        totalProperty: 'count'
    }
    Note that you can save yourself a bit of config if you call your total property total as that is the default.

    As you have already mentioned, simply returning an array as your response cannot work as there is no way to pass the total number of results to the store.

  10. #9
    Ext JS Premium Member tvanzoelen's Avatar
    Join Date
    Apr 2008
    Location
    Groningen - Netherlands
    Posts
    1,111
    Answers
    83
    Vote Rating
    30
    tvanzoelen has a spectacular aura about tvanzoelen has a spectacular aura about tvanzoelen has a spectacular aura about

      0  

    Default


    Yes you must return a JSON object, but that JSON object also contains a JSON array with your data, a Boolean property and an Int property with your totalcount.

    So, It think you must start struggle again with that JSON thing server side

  11. #10
    Sencha User
    Join Date
    Feb 2011
    Posts
    13
    Vote Rating
    0
    Mathias.Deshayes is on a distinguished road

      0  

    Default


    Yes you need to return a JSONObject which contains your JSONArray. For example for a pagesize equals to 3, the object should be something like :


    Code:
    {success: true,  total: 75, data: [{"name":"glsextusr23"},{"name":"GLSEXTUSR36"},{"name":"XBBJVC0"}]}
    The "total" property should return the real total number of users, not just the number of returned users. This total will be used by your grid to display the number of page.