1

I am relatively new to yadcf.
I want to place a search filter on a datatable of type 'auto_complete'. The suggestions offered should be based on an ajax-call based on the clients input.

It seems that the call is not made when I start typing (no request are send to the server).
The suggestions offered are based on the loaded data and not based on the ajax-call.

What am I doing wrong? I can't find a good example.

My code:

yadcf.init(oTable, [{
    column_number: 0,
    filter_default_label: "Enter a familyname...",
    filter_type: "auto_complete",
    filter_plugin_options: {
        source: function( request, response ) {
            $.ajax({
                url: "/bamcers-ajax/familienaam",
                dataType: "json",
                type : 'Get',
                data: { familyname: request.term },
                success: function( data ) { response( data.a );}
            })
        },
        minLength: 2
    }, 
    sort_as: "alpha", 
    style_class: 'width250'
}, columndefs...

Note: This code works fine

$( "#testField" ).autocomplete({
    source: function( request, response ) {
        $.ajax({
            dataType: "json",
            type : 'Get',
            url: '/bamcers-ajax/familienaam',
            data: {familienaam: request.term},
            success: function(data) {response( data );}
        });
    },
    minLength: 2
}); 
GuRu
  • 1,880
  • 3
  • 23
  • 32
Mark Smith
  • 487
  • 1
  • 3
  • 16

1 Answers1

0

Looks like the doc are misleading, according to the code filter_plugin_options is not really used in auto_complete

if (columnObj.filter_type === "auto_complete") {
    columnObj.filter_plugin_options = {
        source: $(document).data("yadcf-filter-" + table_selector_jq_friendly + "-" + column_number),
        select: autocompleteSelect
    };
...

https://github.com/vedmack/yadcf/blob/master/src/jquery.dataTables.yadcf.js#L2916 you can open a feature request on github or send a PR

Daniel
  • 36,833
  • 10
  • 119
  • 200