Multiple search value on server side

Multiple search value on server side

marcpiratmarcpirat Posts: 36Questions: 8Answers: 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: 1,706Questions: 0Answers: 310

    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: 36Questions: 8Answers: 0
    edited May 16

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

  • colincolin Posts: 1,706Questions: 0Answers: 310
    edited May 17

    In your initialisation above, you just need to change:

    'type': 'get',
    

    to

    'type': 'POST',
    

    Cheers,

    Colin

Sign In or Register to comment.