diff --git a/web/admin.php b/web/admin.php index 5b53a33a44..122366b88f 100644 --- a/web/admin.php +++ b/web/admin.php @@ -396,7 +396,7 @@ function generate_new_room_form() echo "\n"; echo "\n"; - echo "" . get_vocab("name") . "\n"; + echo '' . get_vocab("name") . "\n"; if (is_admin()) { // Don't show ordinary users the disabled status: they are only going to see enabled rooms @@ -450,10 +450,9 @@ function generate_new_room_form() $html_name = htmlspecialchars($r['room_name']); $href = multisite('edit_room.php?room=' . $r['id']); - // We insert an invisible span containing the sort key so that the rooms will + // We insert a data attribute containing the sort key so that the rooms will // be sorted properly - echo "
" . - "" . htmlspecialchars($r['sort_key']) . "" . + echo '
' . "$html_name" . "
\n"; if (is_admin()) diff --git a/web/edit_users.php b/web/edit_users.php index 0376c129a0..bfbd141787 100644 --- a/web/edit_users.php +++ b/web/edit_users.php @@ -176,11 +176,11 @@ function output_row($row) } $sortname = get_sortable_name($row['display_name']); - $values[] = '' . $display_name_value; + // TODO: move the data-order attribute up into the and get rid of the + $values[] = '' . $display_name_value; // Then the username - $name_value = "" . htmlspecialchars($row['name']) . ""; - $values[] = '' . $name_value; + $values[] = '' . htmlspecialchars($row['name']) . ''; // Other columns foreach ($fields as $field) @@ -1370,8 +1370,8 @@ function get_fieldset_submit_buttons(?int $user_id, $delete=false, $disabled=fal echo ""; // First two columns which are the name and display name - echo '' . get_vocab("users.display_name") . "\n"; - echo '' . get_vocab("users.name") . "\n"; + echo '' . get_vocab("users.display_name") . "\n"; + echo '' . get_vocab("users.name") . "\n"; // Other column headers foreach ($fields as $field) @@ -1387,6 +1387,7 @@ function get_fieldset_submit_buttons(?int $user_id, $delete=false, $disabled=fal case 'level': case 'timestamp': case 'last_login': + // TODO: Switch from using title-numeric to just numeric(?) $heading = '' . $heading . ''; break; default: diff --git a/web/jquery/datatables/plugins.js b/web/jquery/datatables/plugins.js index 3c73c3b081..a441a3eb27 100644 --- a/web/jquery/datatables/plugins.js +++ b/web/jquery/datatables/plugins.js @@ -8,18 +8,17 @@ jQuery.extend( jQuery.fn.dataTableExt.oSort, { "title-string-pre": function ( a ) { return a.match(/title="(.*?)"/)[1].toLowerCase(); }, - + "title-string-asc": function ( a, b ) { return ((a < b) ? -1 : ((a > b) ? 1 : 0)); }, - + "title-string-desc": function ( a, b ) { return ((a < b) ? 1 : ((a > b) ? -1 : 0)); } } ); - $.fn.dataTableExt.oSort['title-numeric-asc'] = function(a,b) { var x = a.match(/title="*(-?[0-9\.]+)/)[1]; var y = b.match(/title="*(-?[0-9\.]+)/)[1]; @@ -36,9 +35,23 @@ $.fn.dataTableExt.oSort['title-numeric-desc'] = function(a,b) { return ((x < y) ? 1 : ((x > y) ? -1 : 0)); }; +// Localised sorting +$.fn.dataTable.ext.order.intl = function ( locales, options ) { + if ( window.Intl ) { + var collator = new window.Intl.Collator( locales, options ); + var types = $.fn.dataTable.ext.type; + + delete types.order['string-pre']; + types.order['string-asc'] = collator.compare; + types.order['string-desc'] = function ( a, b ) { + return collator.compare( a, b ) * -1; + }; + } +}; + + // Filtering plugins $.fn.dataTableExt.ofnSearch['title-numeric'] = function ( sData ) { return sData.replace(/\n/g," ").replace( /<.*?>/g, "" ); }; - diff --git a/web/js/admin.js.php b/web/js/admin.js.php index 0134b2a4d0..a14bbec1c3 100644 --- a/web/js/admin.js.php +++ b/web/js/admin.js.php @@ -13,9 +13,13 @@ ?> $(document).on('page_ready', function() { - + + var tableOptions = {}; var fixedColumnsOptions = {leftColumns: 1}; + + tableOptions.columnDefs = getTypes($('#rooms_table')); + + $.fn.dataTable.ext.order.intl($('body').data('langPrefs')); + dataTable = table.DataTable(mergedOptions); if (fixedColumnsOptions)