cancel
Showing results for 
Search instead for 
Did you mean: 

Grouping based on Date fields in Smart table.

amit5ingh
Participant

Hi All,

I am facing one challenge while grouping the Samrttable data with date fields. The date is not coming in a formatted way(highlighted in yellow) and the grouping functionality is also not working properly(Sorting of the date is working fine).

Please let me know if there is a way to handle Grouping based on Date via annotation or with any other property and also the date formatting while showing in grouping section.

Best Regards,
Amit

Accepted Solutions (0)

Answers (1)

Answers (1)

jayaramu
Explorer

Issue is solved by adding custom grouping function in BeforeRebind event for date columns.

var oSorter = mBindingParams.sorter[0];

//Check if sorter is for Grouping

if (oSorter && oSorter.vGroup) {

var boolGroupApplied = false,

groupObject;

//Replace the Grouping sorter itself

var aCustomColumns = [{

column: "ExtendTo",

text: this.getView().getModel("i18n").getResourceBundle().getText("ALV_table_Extend_Date"),

formatter: "dd.MM.yyyy"

}, {

column: "StartDate",

text: this.getView().getModel("i18n").getResourceBundle().getText("MOTH_Due_Date"),

formatter: "dd.MM.yyyy"

}, {

column: "ConstraintStartDate",

text: this.getView().getModel("i18n").getResourceBundle().getText("MOTH_Earliest_Start"),

formatter: "dd.MM.yyyy"

}, {

column: "ConstraintFinDate",

text: this.getView().getModel("i18n").getResourceBundle().getText("MOTH_Latest_Start"),

formatter: "dd.MM.yyyy"

}];

aCustomColumns.forEach(function (value, key) {

if (value.column === oSorter.sPath) {

boolGroupApplied = true;

groupObject = value;

}

});

if (boolGroupApplied) {

//Replace the Group function

// oSorter.fnGroup = this.mGroupFunctions();

mBindingParams.sorter[0] = new sap.ui.model.Sorter(oSorter.sPath, oSorter.bDescending, function (t1) {

var u1 = t1.getProperty(oSorter.sPath),

o1 = groupObject.text;

var oDateFormat = sap.ui.core.format.DateFormat.getDateInstance({

UTC: true,

pattern: groupObject.formatter

});

u1 = oDateFormat.format(u1);

if (u1 === undefined || u1 === null) {

u1 = "";

}

return {

key: u1,

text: o1 ? o1 + ": " + u1 : u1

};

});

}

}