sort first with exactly phrase
This commit is contained in:
@@ -134,12 +134,35 @@
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function sortSelect2ResultsByStart(data) {
|
||||||
|
const term = $(".select2-container--open .select2-search__field").val();
|
||||||
|
|
||||||
|
if (!term) {
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
|
const search = term.toLowerCase().trim();
|
||||||
|
|
||||||
|
return data.sort(function (a, b) {
|
||||||
|
const textA = (a.text || "").toLowerCase().trim();
|
||||||
|
const textB = (b.text || "").toLowerCase().trim();
|
||||||
|
|
||||||
|
const aStarts = textA.startsWith(search);
|
||||||
|
const bStarts = textB.startsWith(search);
|
||||||
|
|
||||||
|
if (aStarts && !bStarts) return -1;
|
||||||
|
if (!aStarts && bStarts) return 1;
|
||||||
|
|
||||||
|
return textA.localeCompare(textB, "it", { sensitivity: "base" });
|
||||||
|
});
|
||||||
|
}
|
||||||
// Select2 AJAX config for client selects
|
// Select2 AJAX config for client selects
|
||||||
const clientSelect2Config = {
|
const clientSelect2Config = {
|
||||||
placeholder: "Search client...",
|
placeholder: "Search client...",
|
||||||
allowClear: true,
|
allowClear: true,
|
||||||
width: "100%",
|
width: "100%",
|
||||||
minimumInputLength: 0,
|
minimumInputLength: 0,
|
||||||
|
sorter: sortSelect2ResultsByStart,
|
||||||
dropdownCssClass: "select2-dropdown-smaller",
|
dropdownCssClass: "select2-dropdown-smaller",
|
||||||
ajax: {
|
ajax: {
|
||||||
url: "search_clienti.php",
|
url: "search_clienti.php",
|
||||||
@@ -341,6 +364,7 @@
|
|||||||
allowClear: true,
|
allowClear: true,
|
||||||
width: "100%",
|
width: "100%",
|
||||||
minimumInputLength: 0,
|
minimumInputLength: 0,
|
||||||
|
sorter: sortSelect2ResultsByStart,
|
||||||
ajax: {
|
ajax: {
|
||||||
url: "search_customfield_values.php",
|
url: "search_customfield_values.php",
|
||||||
dataType: "json",
|
dataType: "json",
|
||||||
@@ -1133,6 +1157,7 @@
|
|||||||
placeholder: "Seleziona...",
|
placeholder: "Seleziona...",
|
||||||
allowClear: true,
|
allowClear: true,
|
||||||
width: "100%",
|
width: "100%",
|
||||||
|
sorter: sortSelect2ResultsByStart,
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
const items = fixedFieldCache[fieldKey] || [];
|
const items = fixedFieldCache[fieldKey] || [];
|
||||||
|
|||||||
Reference in New Issue
Block a user