Multiple search value on server side

Multiple search value on server side

marcpiratmarcpirat Posts: 51Questions: 18Answers: 0

hi

I use datatable with server side capacity.

I need to do complex search.

Some field exist in the column and some other not...

I have many input text (one by field) and a button to click (i would like when i click it, search start)...

How can take value from theses input text and build an url for datatable

var urlI18n = '/i18n/' + '[(${#authentication.getPrincipal().getLang()})]' + '.json';

var samplingsTable = $('#samplingsTable').DataTable({
    language: {
        "url" :  urlI18n
    },
    'bLengthChange': false, //hide 'show entries dropdown
    'processing': true,
    'serverSide': true,
    'pagingType': 'simple_numbers',
    'dom': 'Bfrtip'
    'ajax': {
        'type': 'get',
        'url': "/samplings",
        'data': function (d) {
            var current = $('#samplingsTable').DataTable();
            d.page = (current != undefined) ? current.page.info().page : 0;
            d.size = (current != undefined) ? current.page.info().length : 5;
            d.sort = d.columns[d.order[0].column].data + ',' + d.order[0].dir;
            d.search=d.search.value;
        }
    },
    'columns': [
        {'data': 'id'}, 
        {'data': 'buildDate'},
        {'data': 'productTypeName'},
        {'data': 'productName'},
        {'data': 'machineName'}
    ]
});

thanks

Replies

  • colincolin Posts: 15,118Questions: 1Answers: 2,583

    Hi @marcpirat ,

    That looks like a good way to go. It would be better to use POST, then the data is sent in the payload, rather than the URL - see this thread here.

    Cheers,

    Colin

  • marcpiratmarcpirat Posts: 51Questions: 18Answers: 0
    edited May 2018

    how i need to declare datatable because i need to do the search before... to get data

  • colincolin Posts: 15,118Questions: 1Answers: 2,583
    edited May 2018

    In your initialisation above, you just need to change:

    'type': 'get',
    

    to

    'type': 'POST',
    

    Cheers,

    Colin

This discussion has been closed.