1. #1
    Sencha User
    Join Date
    Oct 2010
    Posts
    18
    Vote Rating
    0
    Praveen Adivi is on a distinguished road

      0  

    Default Server side sorting with EXTJS, DWR, JAVA

    Server side sorting with EXTJS, DWR, JAVA


    Hi Guys, I am a newbie to EXTJS and I was wondering if there were any examples that could walk me through the process of enabling directional server side sorting using EXTJS, DWR and Java. Thank you guys in advance

  2. #2
    Ext User
    Join Date
    Aug 2010
    Posts
    58
    Vote Rating
    0
    winklerd is on a distinguished road

      0  

    Default


    Server-side sorting has nothing to do with Ext. If Java is your server-side technology, you'll need to do your sorting there. Look at the Collections class and its subclasses. If you have further questions, a Java forum might be better suited to your needs.

  3. #3
    Sencha User
    Join Date
    Oct 2010
    Posts
    18
    Vote Rating
    0
    Praveen Adivi is on a distinguished road

      0  

    Default


    Hi I have a code written in Java that uses Collections.sort() with an appropriate comparator. However, the issue I am facing is that I am unable to figure out how to pass the name/id of the column I am trying to sort along with the direction of the sort to DWR/JAVA. (I know how to sort in java once I get these parameters). I was wondering if you could walk me through what goes in to get this working

  4. #4
    Ext User
    Join Date
    Aug 2010
    Posts
    58
    Vote Rating
    0
    winklerd is on a distinguished road

      0  

    Default


    I've never used DWR, but I'm assuming you'll need to add parameters to your AJAX request. ExtJS has built-in AJAX support. Here's how you'd do it there.

    GET method:
    Code:
    var columnname = 'foo';
    var sortorder = 'ascending';
    Ext.Ajax.request({
        url: '/url/goes/here?columnname=' + columnname + '&sortorder=' + sortorder,
        success: function() {},
        failure: function() {}
    });
    POST method:
    Code:
    var columnname = 'foo';
    var sortorder = 'ascending';
    Ext.Ajax.request({
        url: '/url/goes/here',
        params: {
            columnname: columnname,
            sortorder: sortorder
        },
        success: function() {},
        failure: function() {}
    });

  5. #5
    Sencha User
    Join Date
    Oct 2010
    Posts
    18
    Vote Rating
    0
    Praveen Adivi is on a distinguished road

      0  

    Default


    Thanks winklerd. I was wondering if there is a way of know what column header was clicked on in a Grid for sorting.. and if there is a way I can link this sort to what I am passing to the back end java server
    Last edited by Praveen Adivi; 28 Oct 2010 at 9:36 AM. Reason: related question

  6. #6
    Sencha User
    Join Date
    Aug 2009
    Posts
    480
    Vote Rating
    1
    plalx has a spectacular aura about plalx has a spectacular aura about

      0  

    Default


    Use remoteSort: true as a config option on the store. It will pass a sort param (column name) and a dir param (direction) as POST by default.

  7. #7
    Ext User
    Join Date
    Aug 2010
    Posts
    58
    Vote Rating
    0
    winklerd is on a distinguished road

      0  

    Default


    Ah, didn't realize this was in a Grid. Yeah, scarsick's response is your best bet.

  8. #8
    Sencha User
    Join Date
    Oct 2010
    Posts
    18
    Vote Rating
    0
    Praveen Adivi is on a distinguished road

      0  

    Default


    thanks guys. I will give it a shot and see how it goes.

  9. #9
    Sencha User
    Join Date
    Oct 2010
    Posts
    18
    Vote Rating
    0
    Praveen Adivi is on a distinguished road

      0  

    Default


    Hi guys, like I said I am using DWR between extjs and Java and I am using a DWR proxy to pass the data given to it the loading phase using a JSONreader . Please find a code excerpt where I make the call to the dwr function pasted below

    searchByCatalogStore = new Ext.data.Store({
    proxy: new Ext.ux.data.DwrProxy({
    apiActionToHandlerMap : {
    read : {
    dwrFunction : ProductSearchCatalog.getCatalogSearchData,
    getDwrArgsFunction : function(request) {

    if(clk==true){
    request.params.start=0;
    clk=false;
    }
    var params = request.params;
    return[cID,selectedNode,params.start,params.limit,params.sort , params.dir];
    }
    }
    }
    }),
    reader: new Ext.data.JsonReader({
    totalProperty:'totalRecords',
    root : 'objectsToConvertToRecords',
    fields : [
    {name: 'strMatNo'},
    {name: 'strMatDesc'},
    {name: 'strCustPartNumber'},
    {name: 'strCustPartDescrip'},
    {name: 'strListPrice',type:'float'},
    {name: 'chk'},
    {name: 'strVOLTAGEC'},
    {name: 'strHORSEPOWER'},
    {name: 'strAMPS'},
    {name: 'strHORSEPOWER_HD'},
    {name: 'strAMPS_HD'},
    {name: 'strENCLOSURE'},
    {name: 'strPOWER'},
    {name: 'retrunMsg'}

    ],
    remoteSort:true
    })
    });

    please find my java method signature below
    public JsonReaderResponse<ProductSearchCatalogGridDao> getCatalogSearchData(
    //HttpServletRequest request, HttpServletResponse response,
    String custId,String selectedNode,String strt,String lmt, String sort, String dir)

    {}

    Also,
    in this method I have the following code to sort
    if(sort!=null)
    {

    Collections.sort(data, new ProductComparator());
    }

    The problem I am facing is that the store and dir objects/strings are becoming null even when sorting is requested. Hope you guys can look into the same.


    The sort and dir parameters you guys mentioned turn up as undefined

  10. #10
    Sencha User darthwes's Avatar
    Join Date
    Mar 2010
    Posts
    633
    Vote Rating
    -13
    darthwes can only hope to improve

      0  

    Default


    Use the code brackets.

    Listen to beforeload on the DWRProxy. It gets on argument, params, does that have your sort and dir properties on it?

    sort and dir WILL NOT be passed until you try to sort...
    Wes

Similar Threads

  1. Map JSON to a server side Java Object
    By ddanet in forum Ext 3.x: Help & Discussion
    Replies: 0
    Last Post: 28 Sep 2010, 12:04 PM
  2. Grid, state and server side sorting
    By zerkms in forum Ext 3.x: Help & Discussion
    Replies: 0
    Last Post: 20 Apr 2010, 1:49 PM
  3. Thoughts on dwr or json for java server side
    By sfwalter in forum Community Discussion
    Replies: 18
    Last Post: 27 Jan 2008, 7:51 AM
  4. Server-side sorting for grid (EXT ver1.1.1)
    By shr1975 in forum Ext 1.x: Help & Discussion
    Replies: 4
    Last Post: 18 Oct 2007, 9:20 PM
  5. Access to grid from the server side Java Code
    By ash9122 in forum Ext 1.x: Help & Discussion
    Replies: 1
    Last Post: 3 Jan 2007, 1:01 AM

Thread Participants: 3

Tags for this Thread