mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
feature: Added support for populating selects from ajax (#6557)
fixes: #5264 The issue was all the string concatenation... But I decided to try loading the select via ajax. Seems ok. We could just use something like select2. Opinions? Use this approach or load at page load. I was able to reduce the loading of the 4000 select items from 1.6s to 0.6s on my laptop by optimizing the sql. I added 4000 devices to my database to check this :)
This commit is contained in:
committed by
Neil Lathwood
parent
02d9b36720
commit
2b3ca49bea
@ -1604,3 +1604,27 @@ function get_dashboards($user_id = null)
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate javascript to fill in a select box from an ajax list
|
||||
*
|
||||
* @param string $list_type type of list look in html/includes/list/
|
||||
* @param string $selector jquery selector for the target select element
|
||||
* @param int $selected the id of the item to mark as selected
|
||||
* @return string the javascript (not including <script> tags)
|
||||
*/
|
||||
function generate_fill_select_js($list_type, $selector, $selected = null)
|
||||
{
|
||||
return '$(document).ready(function() {
|
||||
$select = $("' . $selector . '")
|
||||
$.getJSON(\'ajax_list.php?id=' . $list_type . '\', function(data){
|
||||
$.each(data, function(index,item) {
|
||||
if (item.id == "' . $selected . '") {
|
||||
$select.append("<option value=" + item.id + " selected>" + item.value + "</option>");
|
||||
} else {
|
||||
$select.append("<option value=" + item.id + ">" + item.value + "</option>");
|
||||
}
|
||||
});
|
||||
});
|
||||
});';
|
||||
}
|
||||
|
Reference in New Issue
Block a user