I use ag-grid on Reactjs for table display. In the date column, datepicker filter format is mm/dd/yyyy
but i need to change it to dd/mm/yyyy
. I use agDateColumnFilter
for filtering. Date format of data in the rows are correct, they are dd/mm/yyyy but in the filter there is still mm/dd/yyyy
. How can i fix this?
I use GetTextFieldAdvancedTable function for each column in grid.
function GetTextFieldAdvancedTable(
field,
headerName,
width,
editable = false,
hide = false,
sort = "",
rowGroup = false,
rowDrag = false,
filter = "agTextColumnFilter",
menuTabs = ["filterMenuTab"],
filterParams = {
textFormatter: function(r) {
if (r == null) return null;
r = r.replace(new RegExp("İ", "g"), "i");
r = r.replace(new RegExp("Ğ", "g"), "ğ");
r = r.replace(new RegExp("Ç", "g"), "ç");
r = r.replace(new RegExp("I", "g"), "ı");
r = r.replace(new RegExp("Ö", "g"), "ö");
r = r.replace(new RegExp("Ş", "g"), "ş");
r = r.replace(new RegExp("Ü", "g"), "ü");
r = r.toLowerCase();
return r;
}
}
) {
return {
field,
headerName,
width,
editable,
hide,
sort,
rowGroup,
rowDrag,
filter,
menuTabs,
filterParams
};
}
const UpdateDate = () =>
GetTextFieldAdvancedTable(
"updateDate",
trans.t("lblLastUpdateDate"),
120,
false,
false,
"desc",
false,
false,
"agDateColumnFilter",
["filterMenuTab"],
{
browserDatePicker: false,
comparator: function(filterLocalDateAtMidnight, cellValue) {
return compareCellDateAndFilterDateFormat(filterLocalDateAtMidnight, cellValue);
}
}
);
comparator function :
function compareCellDateAndFilterDateFormat(filterLocalDateAtMidnight, cellValue) {
if (cellValue === null) return 0;
const cellDate = cellValue.split(" ")[0];
const filterDateFormat = moment(filterLocalDateAtMidnight).format("DD.MM.YYYY");
return cellDate < filterDateFormat ? -1 : cellDate > filterDateFormat ? 1 : 0;}
here is a screenshot of filter
Thank you.
compareCellDateAndFilterDateFormat(filterLocalDateAtMidnight, cellValue)
. Can you share that function implementation. – Megadeathmm/dd/yyyy
but you wantdd/mm/yyyy
? – Megadeath