@@ -26,7 +26,7 @@ <h1>Countries</h1>
2626 < has-error >
2727 < span class ="error " data-bind ="errorMessage "> </ span >
2828 </ has-error >
29- < is-loaded >
29+ < is-loaded class =" flex-col " >
3030 < input
3131 is ="input-filter "
3232 filter-selector ="table "
@@ -40,6 +40,7 @@ <h1>Countries</h1>
4040 < div class ="responsive-table ">
4141 < data-table
4242 data-bind ="countries "
43+ highlight-class ="highlight "
4344 labels ="Code, Name, Size (KM), Population, Continent "
4445 table-attr ="is=sortable-table,
4546 data-sort-class-odd=row-odd,
@@ -53,7 +54,8 @@ <h1>Countries</h1>
5354 <!-- DataFormsJS Web Components -->
5455 < script type ="module " src ="https://cdn.jsdelivr.net/npm/dataformsjs@4.5.5/js/web-components/url-hash-router.min.js "> </ script >
5556 < script type ="module " src ="https://cdn.jsdelivr.net/npm/dataformsjs@4.5.5/js/web-components/json-data.min.js "> </ script >
56- < script type ="module " src ="https://cdn.jsdelivr.net/npm/dataformsjs@4.5.5/js/web-components/data-table.min.js "> </ script >
57+ <!-- <script type="module" src="https://cdn.jsdelivr.net/npm/dataformsjs@4.5.5/js/web-components/data-table.min.js"></script> -->
58+ < script type ="module " src ="https://dataformsjs.s3-us-west-1.amazonaws.com/js/pre-release/data-table.min.js "> </ script >
5759 < script type ="module " src ="https://cdn.jsdelivr.net/npm/dataformsjs@4.5.5/js/web-components/input-filter.min.js "> </ script >
5860 < script type ="module " src ="https://cdn.jsdelivr.net/npm/dataformsjs@4.5.5/js/web-components/sortable-table.min.js "> </ script >
5961
@@ -72,14 +74,15 @@ <h1>Countries</h1>
7274 // [contentReady === true] can happen on the first page load if the
7375 // data loads very fast - (before <script type="module"> finished loading).
7476 if ( jsonData . contentReady ) {
75- showTableImages ( ) ;
77+ updateTableContent ( ) ;
7678 } else {
77- jsonData . addEventListener ( 'contentReady' , showTableImages ) ;
79+ jsonData . addEventListener ( 'contentReady' , updateTableContent ) ;
7880 }
7981 }
8082
81- // Add Flag Images to the <table> once it has been rendered.
82- async function showTableImages ( ) {
83+ // Add Flag Images to the <table> once it has been rendered
84+ // and format Number Columns in User's local number format.
85+ async function updateTableContent ( ) {
8386 // Wait till all web components are setup
8487 await componentsAreSetup ( ) ;
8588
@@ -89,15 +92,34 @@ <h1>Countries</h1>
8992 return ;
9093 }
9194
92- // Add flags to all rows
93- const tableRows = table . tBodies [ 0 ] . rows ;
94- const rowCount = tableRows . length ;
95- for ( let x = 0 ; x < rowCount ; x ++ ) {
96- const row = tableRows [ x ] ;
95+ // Find Number and Date Columns so the data can be formatted
96+ const updateCols = [ ] ;
97+ const cells = table . tHead . rows [ 0 ] . cells ;
98+ const colCount = cells . length ;
99+ for ( let x = 0 ; x < colCount ; x ++ ) {
100+ switch ( cells [ x ] . textContent ) {
101+ case 'Size (KM)' :
102+ case 'Population' :
103+ updateCols . push ( x ) ;
104+ break ;
105+ }
106+ }
107+ const updateColLen = updateCols . length ;
108+
109+ // Process all rows
110+ for ( const row of table . tBodies [ 0 ] . rows ) {
111+ // Add flag to row
97112 const iso = row . cells [ 0 ] . textContent . trim ( ) . toLowerCase ( ) ;
98113 const flag = document . createElement ( 'i' ) ;
99114 flag . className = iso + ' flag' ;
100115 row . cells [ 1 ] . insertAdjacentElement ( 'afterbegin' , flag ) ;
116+
117+ // Format Numbers
118+ for ( let y = 0 ; y < updateColLen ; y ++ ) {
119+ const numValue = row . cells [ updateCols [ y ] ] . textContent ;
120+ row . cells [ updateCols [ y ] ] . setAttribute ( 'data-value' , numValue ) ; // Value for Sorting
121+ row . cells [ updateCols [ y ] ] . textContent = Number ( numValue ) . toLocaleString ( ) ; // Value for Display
122+ }
101123 }
102124 }
103125 </ script >
0 commit comments