@@ -49,8 +49,8 @@ async function initExamDashboard(config) {
4949 dynamicTyping : true ,
5050 skipEmptyLines : true ,
5151 complete : ( results ) => {
52- // Initialize Table and Chart with parsed data
53- setupDashboard ( results . data , csvText , config ) ;
52+ // Pass meta.fields so column order matches the CSV header exactly
53+ setupDashboard ( results . data , csvText , config , results . meta . fields ) ;
5454 }
5555 } ) ;
5656 } catch ( err ) {
@@ -60,12 +60,14 @@ async function initExamDashboard(config) {
6060 }
6161}
6262
63- function setupDashboard ( data , rawCsv , config ) {
63+ function setupDashboard ( data , rawCsv , config , csvFields ) {
6464 const { dom, columns, chart : chartConfig } = config ;
6565 const $table = $ ( dom . table ) ;
6666
6767 // --- A. Setup DataTable ---
68- const headers = Object . keys ( data [ 0 ] || { } ) ;
68+ // Use csvFields (PapaParse meta.fields) to preserve CSV column order.
69+ // Object.keys() on parsed rows hoists numeric-looking keys (grades 9,8,7…) first.
70+ const headers = csvFields || Object . keys ( data [ 0 ] || { } ) ;
6971 // Filter out columns if needed (e.g., hiding internal codes), currently showing all
7072 const dtColumns = headers . map ( h => ( { data : h , title : h } ) ) ;
7173
@@ -83,16 +85,17 @@ function setupDashboard(data, rawCsv, config) {
8385 autoWidth : false
8486 } ) ;
8587
86- // Inject "Component" Filter into Table Controls (Only if component col exists)
88+ // Inject component filter into Table Controls (Only if component col exists)
8789 if ( columns . component ) {
8890 const compColIdx = headers . indexOf ( columns . component ) ;
8991 if ( compColIdx > - 1 ) {
9092 const uniqueComps = new Set ( data . map ( r => r [ columns . component ] ) . filter ( Boolean ) ) ;
9193 const filterId = `dt-filter-${ Math . random ( ) . toString ( 36 ) . substr ( 2 , 5 ) } ` ;
92-
94+ const compLabel = columns . componentLabel || 'Component' ;
95+
9396 // Append generic filter input to DataTables wrapper
9497 $ ( dom . table + '_filter' ) . append ( `
95- <label class="ml-4 font-semibold text-sm">Component:
98+ <label class="ml-4 font-semibold text-sm">${ compLabel } :
9699 <input id="${ filterId } " list="${ filterId } -list" class="border rounded px-2 py-1 ml-1 w-24 sm:w-32 bg-gray-50 dark:bg-gray-700 dark:border-gray-600" placeholder="Filter">
97100 </label>
98101 <datalist id="${ filterId } -list"></datalist>
0 commit comments