Data Table with Sort/Filter

Build a sortable and filterable data table

IntermediateTopic: Mini Projects
Back

JavaScript Data Table with Sort/Filter Program

This program helps you to learn the fundamental structure and syntax of JavaScript programming.

Try This Code
class DataTable {
    constructor(data) { this.data = data; this.sortedBy = null; this.filter = ''; }
    sort(column) { this.sortedBy = column; this.data.sort((a, b) => a[column] - b[column]); }
    filterData(query) { this.filter = query; return this.data.filter(row => Object.values(row).some(v => String(v).includes(query))); }
}
Output
// Data table functionality

Understanding Data Table with Sort/Filter

Data Table displays sortable and filterable data.

Note: To write and run JavaScript programs, you need to set up the local environment on your computer. Refer to the complete article Setting up JavaScript Development Environment. If you do not want to set up the local environment on your computer, you can also use online IDE to write and run your JavaScript programs.

Table of Contents