File tree Expand file tree Collapse file tree 2 files changed +20
-2
lines changed
Expand file tree Collapse file tree 2 files changed +20
-2
lines changed Original file line number Diff line number Diff line change @@ -35,7 +35,22 @@ function table_search_sort(el) {
3535 el,
3636 sort_keys : sort_buttons . map ( ( b , idx ) => {
3737 const sort_key = cells [ idx ] ?. textContent ;
38- return { num : Number . parseFloat ( sort_key ) , str : sort_key } ;
38+ const num = Number . parseFloat ( sort_key ) ;
39+ // if the user requested for this column to be formatted using `toLocaleString()`,
40+ // we replace the cell contents
41+ if ( cells [ idx ] ?. hasAttribute ( "number-format-locale" ) && ! Number . isNaN ( num ) ) {
42+ const digits = cell . getAttribute ( "number-format-digits" ) ;
43+ // The variable `digits` can be left empty or contain an integer
44+ const options = digits
45+ ? { minimumFractionDigits : digits , maximumFractionDigits : digits }
46+ : { } ;
47+ // Use the host default language, with the options we just defined
48+ cell . innerHTML = num . toLocaleString ( undefined , options ) ;
49+ }
50+ return {
51+ num,
52+ str : sort_key ,
53+ } ;
3954 } ) ,
4055 } ;
4156 } ) ;
Original file line number Diff line number Diff line change 5353 <td class =" align-middle {{ @key ~}}
5454 {{ ~#if (array_contains_case_insensitive ../../align_right @key )}} text-end {{ /if ~}}
5555 {{ ~#if (array_contains_case_insensitive ../../align_center @key )}} text-center {{ /if ~}}
56- " >
56+ "
57+ {{ ~#if (array_contains_case_insensitive ../../number_format_locale @key )}} number-format-locale {{ /if ~}}
58+ number-format-digits ={{ ../../number_format_digits }}
59+ >
5760 {{ ~#if (array_contains_case_insensitive ../../markdown @key )~}}
5861 {{{ markdown this }}}
5962 {{ ~else ~}}
You can’t perform that action at this time.
0 commit comments