Select2 with large data set
Select2 with large data set
Hi,
I'm trying to use the Select2 plugin, but I'm facing some issues. I'm trying to use it with a large data set, 35.000+, however it's buggy and gives the Script timeout error. I do also face the following problems:
The field in the editor form is gone/blank. You can however click on it and the field do work, but still buggy as told.
I'm also trying to paginate it, however it doesn't work on the field. If I use the same code on a field not associated with Datatables, then the pagination works.
I've read more or less every page in this forum about Select2, and followed the documentation in https://editor.datatables.net/plug-ins/field-type/editor.select2 but couldn't find a solution. In this thread https://datatables.net/forums/discussion/54967 from a month ago, describes some of the issues regarding Select2.
I'm using Editor-PHP 1.9.0 and Datatables 1.10.18.
Below is my code, and I'm not sure how to proceed from here.
let editor = $(document).ready(function () {
editor = new $.fn.dataTable.Editor({
ajax: {
create: {
type: 'POST',
url: '../backend/backendCRUD/intranetCRUD/create.php'
},
remove: {
type: 'POST',
url: '../backend/backendCRUD/intranetCRUD/remove.php?id=_id_'
},
edit: {
type: 'POST',
url: '../backend/backendCRUD/intranetCRUD/edit.php?id=_id_'
}
},
table: "#intranet",
fields: [
{
"label": "Kundenummer:",
"name": "crapper_customer_intranet.kundenr"
},
{
"label": "Navn:",
"name": "crapper_customer_intranet.navn",
type: 'select2',
"opts": {
"ajax": {
url: "../backend/dependentTest.php",
dataType: 'json',
data: function (params) {
return {
param: params.term,
page: params.page || 1,
rows: 10
};
},
processResults: function (data, params) {
console.log(data.data);
params.page = params.page || 1;
var listTR = Array();
data.data.forEach(function(dataTR, i) {
listTR[i] = {
"text": dataTR.navn,
"id": dataTR.kundenr
};
});
return {
results: listTR,
pagination: {
more: params.page < data.total
}
};
},
minimumInputLength: 5,
maximum: 10,
delay: 500,
maximumSelectionLength: 5,
minimumResultsForSearch: -1,
},
"theme": "bootstrap",
"multiple":false,
}
},
This question has an accepted answers - jump to answer
Answers
To confirm - is the problem that the initial value when you click edit for a row is not shown? Or have I misunderstood?
Does your
dependentTest.php
script specifically handle theinitialValue
request that the Select2 integration for Editor makes?Thanks,
Allan
hi @allan
Nevermind the field, I fixed it.
I've changed my code according to the documentation and with other options.
I'm testing with the following serverScript:
It does make the ajax call but the select2 field keeps being empty.
The data returned from the server:
If I change the return value in ProcessResults
from
to
Then it works! However it still is really buggy and gives the ScriptTimeout error and stops the page from loading..
As you asked my server script doesn't handle the InitialValue request. I've searched throughout the forum to find a solution since I'm not sure how to handle the request.. The request is the following:
I'm guessing the problem is my server script...
Ty in advance!
// Svendber
The issue here is that the Editor PHP libraries don't attempt to handle the Select2 Ajax requests at all. In future I might expand them to do so, so we can more tightly align with Select2 (as you are seeing its not trivial to get it working atm), but just now you need to make your own PHP script that will answer the Select2 requests for data, just as you would if you weren't using Editor.
Allan