Override ListGrid sort

I should like to have server side sorting. I tried to override the ListGrid’s sort method to achieve server-side ordering of the elements. I set this.sortFieldNum and this.sortDirection, but it doesn’t work properly. The header does not change, neither the sort icon shows up. The showSortArrow property is set to “both”.

Anyone can please help with setting up a basic server-side sorting scenario? Thanks much in advance!

Hi szokea,
Server side sorting should essentially “just work” for you.
You can see it in action by hitting any of our databound grid examples (say this one), and modifying sortFieldNum (to 0 or 1, say), and sortDirection to either "ascending"or “descending”.

No override of the ListGrid.sort() method should be required.

Note: If you’re writing a custom back end to retrieve your data from the server, you can determine the requested sort fields / direction via the DSRequest.getSortByFields() method.

Let us know if you need more info
Thanks
Isomorphic Software

sort on server side using SEAM as server

Thanks your answer. The root of my problem is we use JBoss SEAM on the server side. The SEAM provides AJAX functionality. We doesn’ t use SmartClient’s server side. What can you suggest in such a scenario.
Can we override the SmartClient DataSource fetch operation?

Thanks in advance

Hi szokea
The AJAX functionality provided by SEAM will work directly with the bulid-in JSF components, but not with SmartClient components.
The best way to integrate SmartClient components with a JBoss/SEAM server is to install the SmartClient back end and use Spring based DMI integration.
An overview of integration with Spring can be found here.

In this situation you will recieve a SmartClient DSRequest on the server when the sort / fetch operation occurs, that contains the requested sort fields / direction (see getSortByFields()) which you would then pass on to your back-end.
A complete example is provided for the similar situation of integrating with Hibernate. (See docs here and the example code in the SDK at http://[host:port]/examples/server_integration/index.html#springDSHiberateDMI)

I hope this is clear - please feel free to respond with further questions, or if you encounter any difficulties with the integration.

SmartClient and SEAM

Thanks for answer.

SEAM has a remoting feature. This uses a remote.js on client side and @WebRemote annotation on server side. I can load data into ListrGrid this way by calling it’s setData function.

This works:

isc.ClassFactory.defineClass(“PersonGrid”, isc.ListGrid);
isc.PersonGrid.addProperties({
ID: “personGrid”,
…
canSort: false,
sortFieldNum: 1,
showSortArrow: “both”,
sortDirection: Array.ASCENDING,

fields:[
{name: "id", title: "ID", type: "integer"},
{name: "nev", title: "Name"},
{name: "email", title: "E-mail address"},
{name: "birthDate", title: "Birth date", type: "date"}
],

callBack: function (gridInfo) {

    this.setData(gridInfo.data);

    this.sortFieldNum = gridInfo.sortFieldnum;
    if (gridInfo.sortDirection > 0)
        this.sortDirection = Array.ASCENDING;
    else
        this.sortDirection = Array.DESCENDING;

    this.canSort = true;
    this.markForRedraw();
},

fillGrid: function() {
    var me = this;
    var SEAMbean = Seam.Component.getInstance("personFacade");

    var direction = 1;
    if (me.sortDirection == Array.DESCENDING) direction = -1;

    // Call SEAM by AJAX
    SEAMbean.getGridInfo(me.sortFieldNum, direction,
            function(gridInfo) {            // SEAM AJAX callback
                me.callBack(gridInfo);    
            }
    );
},

…
});

Unfortunatelly the fillGrid function needs to be called.
I’d like to use the autoFetchData feature.

Hi
Yes - this approach will work - essentially you’re getting the data into the browser via the SEAM remoting feature, and then applying it to the ListGrid as client-side data.

However you should be aware that this approach doesn’t support a number of the client-server features buillt into the SmartClient ResultSet and RPCManager class.
For example: paging of server side data (loading very large lists incrementally as they come into view), integrated editing of server data, batching of server-data requests, and various other features.
For this reason we would recommend the Spring integration strategy described earlier in preference to this one.

To answer your specific question, however, the autoFetchData feature ensures that when the grid is first drawn, it requests data from the server. You can achieve equivalent functionality by overriding the draw() method on your grid to call your own fillGrid() function. Something like this:

isc.ListGrid.create({
    ID:"myGrid", 
    // various properties
    draw:function () {
        // Kick off a fetch
        fillGrid();
        // Call the Superclass implementation to actually draw the grid
        return this.Super("draw", arguments);
    }
})

SEAM remoting feature

Hi

unfortunately I have to stick with SEAM remoting instead of using the provided RPCManager. But for this to work properly, I need to know what
methods was designed for overwriting (eg. fetchData), what method arguments I can use at the callback method and what I can do with them to update the datasource.

Hi szokea,

While you can override ListGrid.fetchData like any other method, and fire the dsCallback via fireCallback like any other callback, this approach is a lot of work. Aside from doing your own paging, sorting and cache management via setData(), as you’ve already started on, you’ll need to handle validation errors and cache update on saves.

Is you can share the reason you’ve eliminated both the server-side and client-side integration pathways built into SmartClient, maybe we can clear up some misconception that will help you avoid the much, much more difficult approach you’ve chosen.

SEAM and SmartClient

Hi,

Yes, we have more reason to use SEAM. It has conversation context, component injection, built in pageflow for navigation. We should like to use these features. This works if requests are received over the servlet used by SEAM. Our conception is to realize the autoFetch, paging, etc. SmartClient features on the base of SEAM remoting.

We would happy if You helped us to realize this goal.

Thanks
András Szőke

Hi szokea,

It doesn’t seem that conversation context (aka current state of components), component injection or pageflow apply to ListGrid data paging. Furthermore, in the SmartClient Architecture, conversation context does not need to be sent to or preserved by the server, and pageflow is accomplished completely client side.

These are the reasons why SmartClient achieves much better responsiveness and scalability than any JSF-based AJAX solution can - far fewer server round trips.

While you can use SEAM remoting with SmartClient via the approach previously outlined, it creates a lot of extra work and will yield an inferior solution - we still recommend standard SmartClient integration.