Up/down sorting doesn't work on wicket - AjaxFallBackTable

I have a problem with Ajaxfallbacktable - the pagenation is working fine - the data loading - everything is easy as pie - even the default sorting works - but I can't figure out how to add updown buttons in every column - so that I can sort the table anyway I want Here is my table

        List<IColumn<logParsed>> columns = new ArrayList<IColumn<logParsed>>();

        columns.add(new PropertyColumn<logParsed>(new Model<String>("Number of Entries"), "numberOfEntries") {
            @Override
            public String getCssClass()
            {
                return "numeric";
            }
        });
        columns.add(new PropertyColumn<logParsed>(new Model<String>("Last Seen"), "lastSeen"));
        columns.add(new PropertyColumn<logParsed>(new Model<String>("Host Name"), "hostName") {
            @Override
            public String getCssClass()
            {
                return "hostname";
            }
        });
        columns.add(new PropertyColumn<logParsed>(new Model<String>("Log Message"), "logMessage"));


        logProvider<logParsed> LogProvider = new logProvider<logParsed>(logParsedDao.findAll());
        final AjaxFallbackDefaultDataTable<logParsed> dataTable = new AjaxFallbackDefaultDataTable<logParsed>("table", columns, 
                LogProvider, 10) {
            /**
             * 
             */
            private static final long serialVersionUID = 1L;

            @Override
            protected Item<logParsed> newRowItem(String id, int index, IModel<logParsed> model) {
                return new OddEvenItem<logParsed>(id, index, model);
            }
        };

       /* add(new OrderByBorder("sortByHighest", "numberOfEntries", LogProvider)
        {
            private static final long serialVersionUID = 1L;

            @Override
            protected void onSortChanged()
            {
               dataTable.setCurrentPage(0);
            }
        }); */
        add(dataTable);

====

Here is my dataprovider

  public class LogProvider<logParsed> extends SortableDataProvider{

/**
 * 
 */
private static final long serialVersionUID = 1L;
private LogParsedDao logParsedDao;





private List<logParsed> list =  new ArrayList<logParsed>();

public LogProvider(List<logParsed> sentList){

    setSort("numberOfEntries",SortOrder.DESCENDING);
    list = sentList;
}

public Iterator iterator(int first, int count) {

    //ArrayList<logParsed> newList = (ArrayList<logParsed>) logParsedDao.findAll();
    //Collections.sort(newList, comparator);
    Iterator<logParsed> iterator = null;

    try {
        if(getSort() != null) {
            Collections.sort(list, new Comparator<logParsed>() {
                private static final long serialVersionUID = 1L;

                    public int compare(logParsed sl1, logParsed sl2) {
                     int result=1;
                        PropertyModel<Comparable> model1= new PropertyModel<Comparable>(sl1, getSort().getProperty());
                        PropertyModel<Comparable> model2= new PropertyModel<Comparable>(sl2, getSort().getProperty());

                        if(model1.getObject() == null && model2.getObject() == null) 
                            result = 0;
                        else if(model1.getObject() == null) 
                            result = 1;
                        else if(model2.getObject() == null) 
                            result = -1;
                        else 
                            result = ((Comparable)model1.getObject()).compareTo(model2.getObject());

                        result = getSort().isAscending() ? result : -result;

                        return result;
                }
            });
        }

        if (list.size() > (first+count))
            iterator = list.subList(first, first+count).iterator();
        else
            iterator = list.iterator();
    } 
    catch (Exception e) {
        e.printStackTrace();
    }

    return iterator;

}

public int size() {
    // TODO Auto-generated method stub
    return list.size();
}

public IModel model(final Object object) {
    return new AbstractReadOnlyModel<logParsed>() {
        @Override
        public logParsed getObject() {
            return (logParsed) object;
        }
    };
}

}

Answers


Use the PropertyColumn constructor that receives the sort property: PropertyColumn(displayModel, sortProperty, propertyExpression).


Need Your Help

where does git-svn save ssh credentials?

security git ssh git-svn

I am using git-svn to develop code that is hosted on a SVN+SSH repository. I do not have to input my ssh password on the server every time I dcommit/update/rebase, so I assume it is cached somewher...

How does CONTENT-AWARE FILL work in Photoshop?

c# windows photoshop fill

I really enjoy programming in C#. After working with Photoshop CS5 - Content Aware I got insanely curious about the way it works. I tried many ways to find it out myself but the amazing-ness of thi...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.