How to Sort Datasource Based on Date Time in JavaScript Timeline?
This article explains how to sort a datasource based on dateTime in JavaScript Timeline.
[index.js]
// Function to parse datetime strings
function parseDateTime(datetime) {
return new Date(datetime);
}
// Function to sort data based on datetime values
function sortDatasByDateTime(data) {
return data.sort((a, b) => {
const dateA = parseDateTime(a.datetime);
const dateB = parseDateTime(b.datetime);
return dateA - dateB;
});
}
// Sort datas array
datas = sortDatasByDateTime(datas);
var defaultTimeline = new ej.layouts.Timeline({
items: datas,
orientation: 'Horizontal',
});
defaultTimeline.appendTo('#default');
Refer to the working sample for additional details and implementation: Timeline-SortedDatasource
See Also :
Conclusion
We hope you enjoyed learning how to sort datasource based on date time in JavaScript Timeline
You can refer to our JavaScript Timeline feature tour page to know about its other groundbreaking feature representations and documentation, and how to quickly get started for configuration specifications. You can also explore our JavaScript Timeline example to understand how to create and manipulate data.For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls.
If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forums, BoldDesk Support, or feedback portal. We are always happy to assist you!