Suggestion/Autocomplete option values for input

Suggestion/Autocomplete option values for input

CapamaniaCapamania Posts: 233Questions: 81Answers: 5

I'm appending options to an input to show suggestions when searching for a value. The below is looking only in the current json though ... (so the first 100 values (at beginning) out of 10000 records). Is it possible to not limit the values to 100 and use the whole returning name.php ?

<input class="input-name form-control" list="datalist-name" type="text">
<datalist id="datalist-name"></datalist>

table = $('#my_table').DataTable( {
        dom: "Blfrtip",   
        ajax: {
              url: "/name.php",
              type: "POST",
              data: function (d) {  } },
        serverSide: true,
        processing: true,
        columns: [
            ...
        ],
        lengthMenu: [100, 250, 500],
        'initComplete': function(settings, json) {
            
        $.each(json.data, function (i, item) {
            var name = item.name;
        $('#datalist-name').append('<option value="' + name + '">' + name + ' </option>');
            
            });
            
        }                                                    
    } ); 

Many thanks

This question has accepted answers - jump to:

Answers

  • allanallan Posts: 63,542Questions: 1Answers: 10,476 Site admin

    Are you using the Editor PHP libraries (you'll have told me in another thread, I just can't remember!)? If so, 1.6 has a new limit option that you could use.

    Allan

  • CapamaniaCapamania Posts: 233Questions: 81Answers: 5

    Hi Allan. Yes, I'm using the 1.6 Editor version. By 'options' I just meant appending the values to <option value="' + name + '">' + name + ' </option> in datalist. So the values come from column "name" ...

    columns: [
         { data: "name"}
    ....
     ],
    

    Not from Editor Field->options().

    Is there maybe a way via ajax.data to get the full list of "names" coming back from name.php ?

  • allanallan Posts: 63,542Questions: 1Answers: 10,476 Site admin
    Answer ✓

    Ah - sorry. I understand now.

    So basically you are running into the fact that you are using server-side processing, which in turn means that only a sub-set (the current page) of rows is returned from the server. If you disable server-side processing, that issue would be resolved. Is that an option? Are you using tens of thousands of rows?

    If it isn't an option you'll need to perform another query on the database to get the options you want to display and have them returned in the JSON.

    Allan

  • CapamaniaCapamania Posts: 233Questions: 81Answers: 5

    Thanks Allan. Deactivating Serverside ( //serverSide: true ) is unfortunately not working. It throws back a DataTables warning. I assume it's due to the amount of data. I got actually close to 500000 records and a number of columns in that table.

    I'll give it a try with a custom query, there are numerous tutorials on autocomplete online like https://www.wowww.nl/2014/02/01/jquery-autocomplete-tutorial-php-mysql/.

    Best Regards

  • allanallan Posts: 63,542Questions: 1Answers: 10,476 Site admin
    Answer ✓

    Yes, if you are into the hundreds of thousands of rows, then you will want server-side processing enabled and you will need to get that extra information to the client-side.

    Allan

This discussion has been closed.