on 03-26-2014 5:20 AM
hi,
i have used datepicker which is binded with json model and displayed with table.
i wanted to sort the dates,is there any method to do it>
?
thanks and regards.
Hi,
You can sort it as strings as in the following example:
// override standard table sorter
oTable.attachSort(function(oEvent) {
var sPath = oEvent.getParameter("column").getSortProperty();
var bDescending = false;
if (oEvent.getParameter("sortOrder") == "Descending") {
bDescending = true;
}
var oSorter = new sap.ui.model.Sorter(sPath, bDescending );
// override compare function only for birthday path
if (sPath === "birthday") {
oSorter.fnCompare = function(a, b) {
// parse to Date object
var aDate = new Date(a);
var bDate = new Date(b);
if (bDate == null) {
return -1;
}
if (aDate == null) {
return 1;
}
if (aDate < bDate) {
return -1;
}
if (aDate > bDate) {
return 1;
}
return 0;
};
}
oTable.getBinding('rows').sort(oSorter);
// prevent internal sorting by table
oEvent.preventDefault();
});
This example was taken from Snippix: http://veui5infra.dhcp.wdf.sap.corp:8080/snippix/#7887
but I attached it just in case you can't access it.
Hope that helps,
Ran
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi
birthday would indicate the path in the model that's relevant to your date.
a & b are the parameters provided to the compare function for determining the order between elements. You don't need to provide these parameters anywhere, this method is called using a sorting algorithm of the table.
Ran
Hi Kartik,
I uploaded the mentioned sample to JSBin, I guess that if you'll see the working code it will answer your questions: JS Bin - Collaborative JavaScript Debugging</title> <link rel="icon" href="h...
Regards,
Ran
Hi,
Could you please tell if I change the pattern of date as dd.MM.yyyy then it is not working.What can be the possible solution.
Thanks
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
84 | |
24 | |
11 | |
9 | |
7 | |
6 | |
5 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.