mirror of
https://github.com/jokob-sk/NetAlertX.git
synced 2025-12-06 17:15:38 -08:00
FE: UI_DEFAULT_PAGE_SIZE #1181
Signed-off-by: jokob-sk <jokob.sk@gmail.com>
This commit is contained in:
@@ -743,7 +743,7 @@ function initializeDatatable (status) {
|
||||
},
|
||||
'paging' : true,
|
||||
'lengthChange' : true,
|
||||
'lengthMenu' : [[10, 20, 25, 50, 100, 500, 100000], [10, 20, 25, 50, 100, 500, getString('Device_Tablelenght_all')]],
|
||||
'lengthMenu' : getLengthMenu(parseInt(getSetting("UI_DEFAULT_PAGE_SIZE"))),
|
||||
'searching' : true,
|
||||
|
||||
'ordering' : true,
|
||||
|
||||
@@ -197,7 +197,7 @@ function initializeDatatable () {
|
||||
$('#tableEvents').DataTable({
|
||||
'paging' : true,
|
||||
'lengthChange' : true,
|
||||
'lengthMenu' : [[10, 25, 50, 100, 500, -1], [10, 25, 50, 100, 500, 'All']],
|
||||
'lengthMenu' : getLengthMenu(parseInt(getSetting("UI_DEFAULT_PAGE_SIZE"))),
|
||||
'searching' : true,
|
||||
'ordering' : true,
|
||||
'info' : true,
|
||||
|
||||
@@ -952,5 +952,41 @@ function initHoverNodeInfo() {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a DataTables-style `lengthMenu` array with an optional custom entry inserted
|
||||
* in the correct numeric order.
|
||||
*
|
||||
* Example output:
|
||||
* [[10, 20, 25, 50, 100, 500, 100000], [10, 20, 25, 50, 100, 500, 'All']]
|
||||
*
|
||||
* @param {number} newEntry - A numeric entry to insert into the list (e.g. 30).
|
||||
* If it already exists or equals -1, it will be ignored.
|
||||
* @returns {Array[]} A two-dimensional array where:
|
||||
* - The first array is the numeric page lengths.
|
||||
* - The second array is the display labels (same values, but 'All' for -1).
|
||||
*
|
||||
* @example
|
||||
* getLengthMenu(30);
|
||||
* // → [[10, 20, 25, 30, 50, 100, 500, 100000], [10, 20, 25, 30, 50, 100, 500, 'All']]
|
||||
*/
|
||||
function getLengthMenu(newEntry) {
|
||||
const values = [10, 20, 25, 50, 100, 500, 100000];
|
||||
const labels = [10, 20, 25, 50, 100, 500, getString('Device_Tablelenght_all')];
|
||||
|
||||
// Insert newEntry in sorted order, skipping duplicates and -1/'All'
|
||||
const insertSorted = (arr, val) => {
|
||||
if (val === -1 || arr.includes(val)) return arr;
|
||||
const idx = arr.findIndex(v => v > val || v === -1);
|
||||
if (idx === -1) arr.push(val);
|
||||
else arr.splice(idx, 0, val);
|
||||
return arr;
|
||||
};
|
||||
|
||||
insertSorted(values, newEntry);
|
||||
insertSorted(labels, newEntry);
|
||||
|
||||
return [values, labels];
|
||||
}
|
||||
|
||||
|
||||
console.log("init ui_components.js")
|
||||
@@ -74,7 +74,8 @@ require 'php/templates/header.php';
|
||||
|
||||
$(document).ready(function() {
|
||||
const table = $('#notificationsTable').DataTable({
|
||||
"pageLength": parseInt(getSetting("UI_DEFAULT_PAGE_SIZE")) ,
|
||||
"pageLength": parseInt(getSetting("UI_DEFAULT_PAGE_SIZE")),
|
||||
'lengthMenu' : getLengthMenu(parseInt(getSetting("UI_DEFAULT_PAGE_SIZE"))),
|
||||
"columns": [
|
||||
{ "data": "timestamp" ,
|
||||
"render": function(data, type, row) {
|
||||
|
||||
Reference in New Issue
Block a user