how to set columns for search datatables jquery

how to set columns for search datatables jquery

mamadsolimamadsoli Posts: 11Questions: 2Answers: 0

how to set columns for search datatable jquery? i use datatables and my problem is filter multi columns.

i am trying filter all columns in DataTables but only last field send to server for filtering.

function searchRow(selector, formName) {
    var $formId = $('#' + formName + 'Form');
    var formData = new FormData( $formId[0] );
    for (var pair of formData.entries()) {
        table.column(pair[0]).search(pair[1]);
    }
    table.ajax.reload();
}

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,192Questions: 1Answers: 10,412 Site admin

    I don't immediately see any problem with that code. Could you create a test case on http://live.datatables.net or give me a link to some other page that shows that issue please.

    Allan

  • mamadsolimamadsoli Posts: 11Questions: 2Answers: 0
    edited October 2019

    address in live is:

    http://live.datatables.net/camucuka/1/edit

    This is obvious
    This only searches the last field

  • kthorngrenkthorngren Posts: 21,166Questions: 26Answers: 4,921

    Not sure why but in your test case the pair variable doesn't seem to populate with the values in the inputs. But the example does highlight what you are tying to do, I think. I added a console log statement to see how the formData loop is working:
    http://live.datatables.net/camucuka/2/edit

    I updated your test case using the server side example provided in this technote. I also manually created an array for the loop (didn't want to take the time to debug the formData you are using).
    http://live.datatables.net/cuxolaxa/1/edit

    With two column searches defined:

            table.column(2).search('Software Engineer');
            table.column(3).search('London');
    

    You can see both search values are sent to the server:

    columns[2][data]: 2
    columns[2][name]: 
    columns[2][searchable]: true
    columns[2][orderable]: true
    columns[2][search][value]: Software Engineer
    columns[2][search][regex]: false
    columns[3][data]: 3
    columns[3][name]: 
    columns[3][searchable]: true
    columns[3][orderable]: true
    columns[3][search][value]: London
    columns[3][search][regex]: false
    

    Also you will want to use draw() instead of ajax.reload() to perform the search.

    Kevin

  • mamadsolimamadsoli Posts: 11Questions: 2Answers: 0

    thankyou allan , I could do it with your guidance

    http://live.datatables.net/qadoxalu/5/edit

  • colincolin Posts: 15,237Questions: 1Answers: 2,598
    Answer ✓

    Hi @mamadsoli ,

    That link looks like it's behaving to me - I corrected the column headings here. Where do you think it's not behaving?

    Cheers,

    Colin

  • mamadsolimamadsoli Posts: 11Questions: 2Answers: 0

    hi dear friend
    you use draw() instead of ajax.reload() .

    Anyway thank you very match.

This discussion has been closed.