-
-
Notifications
You must be signed in to change notification settings - Fork 240
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Get value sorter type by fact itself when datatable_init
- Loading branch information
1 parent
b8e1467
commit c457ece
Showing
5 changed files
with
60 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/** | ||
* Created by Allan Jardine on Feb 17, 2023. | ||
* Updated @ Feb 22, 2024 | ||
* Modified for the Puppetboard by ArthurWuTW. | ||
*/ | ||
|
||
/** | ||
* Data can often be a complicated mix of numbers and letters (file names | ||
* are a common example) and sorting them in a natural manner is quite a | ||
* difficult problem. | ||
* | ||
* Fortunately the Javascript `localeCompare` method is now widely supported | ||
* and provides a natural sorting method we can use with DataTables. | ||
* | ||
* @name Natural sorting | ||
* @summary Sort data with a mix of numbers and letters _naturally_. | ||
* | ||
* @example | ||
* // Natural sorting | ||
* new DataTable('#myTable', | ||
* columnDefs: [ | ||
* { type: 'natural', target: 0 } | ||
* ] | ||
* } ); | ||
* | ||
*/ | ||
|
||
|
||
jQuery.extend(jQuery.fn.dataTableExt.oSort,{ | ||
|
||
"natural-asc" : function (a, b) { | ||
return a.localeCompare(b, navigator.languages[0] || navigator.language, { | ||
numeric: true, | ||
ignorePunctuation: true, | ||
}); | ||
}, | ||
|
||
"natural-desc" : function (a, b) { | ||
return (a.localeCompare(b, navigator.languages[0] || navigator.language, { numeric: true, ignorePunctuation: true }) * | ||
-1); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{% macro get_facts_sorter_type(fact) -%} | ||
|
||
{% set sorter_map = { | ||
'kernelrelease': 'natural', | ||
'uptime': 'natural-time-delta' | ||
} %} | ||
|
||
{% set sorter = sorter_map.get(fact, None) %} | ||
{% if sorter != None %} | ||
"type": "{{ sorter }}", | ||
{% endif %} | ||
{%- endmacro %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters