DataTable Search Doesnot work

DataTable Search Doesnot work

anim_95anim_95 Posts: 6Questions: 2Answers: 0

Datatable Search doesnot work when td value is <td><input type="text"/></td>. Please tell me what is the solution

This question has an accepted answers - jump to answer

Answers

  • colincolin Posts: 14,303Questions: 1Answers: 2,431

    Thanks for your question. As noted in the forum rules, please post a link to a running test case showing the issue so we can offer some help. Information on how to create a test case (if you aren't able to link to the page you are working on) is available here.

    Cheers,

    Colin

  • anim_95anim_95 Posts: 6Questions: 2Answers: 0

    http://live.datatables.net/qujewege/1/edit
    this is the live link here search does not work

  • colincolin Posts: 14,303Questions: 1Answers: 2,431

    Thanks for the live link. DataTables is intended to be used with read-only data, and Editor if that data is to be edited. I may be missing something, but why would you want those table cells to be input types on a DataTable?

    Cheers,

    Colin

  • anim_95anim_95 Posts: 6Questions: 2Answers: 0

    As per the requirement from the mentor I have to use textboxs in table. Is there any solution for this problem?

  • colincolin Posts: 14,303Questions: 1Answers: 2,431

    It's not a problem as such, since it's not being used in the way intended. If the intention is to get the styling of an input box, you could just style those TD elements with some CSS.

  • allanallan Posts: 56,200Questions: 1Answers: 8,902 Site admin

    Not at this time sorry. Ordering does have that ability, but not yet for search.

    Allan

  • kthorngrenkthorngren Posts: 16,109Questions: 25Answers: 3,815
    edited February 2018 Answer ✓

    In addition to the ordering link Allan provided you can use columns.render to get the .val() of the input and return that for the filter operation. In order for this to work you will need an event handler to update the value attribute of the input and to use cell().invalidate(), along with draw(), to have Datatables update it's cache and re-sort the table.

    Something like this for the render function:

            render: function (data, type, row, meta) {
              if (type === 'filter') {
                return $(data).val();
              }
              return data;
          }
    

    Kevin

  • anim_95anim_95 Posts: 6Questions: 2Answers: 0

    Thanks kthorngren this works absolutely fine for me

  • colincolin Posts: 14,303Questions: 1Answers: 2,431
    edited February 2018

    For prosperity, I was playing around with Kevin's suggestion, here it is:

    http://live.datatables.net/yecayovo/3/edit

  • kthorngrenkthorngren Posts: 16,109Questions: 25Answers: 3,815

    There are a couple things needed for the example to completely work. The 'input' ordering needs setup as described in the example Allan pointed to. Also for the filtering to work the input value attribute needs to be updated for the render function to have the correct value.

    Updated example:
    http://live.datatables.net/yupezaci/1/edit

    Kevin

  • colincolin Posts: 14,303Questions: 1Answers: 2,431

    Gotcha, I didn't understand why the invalidate was needed, but yep, that's when you change the cell data! I get there, slowly :smile:

This discussion has been closed.