Why can't I apply multi column filtering to a dynamically created footer?

Why can't I apply multi column filtering to a dynamically created footer?

dt_userdt_user Posts: 51Questions: 16Answers: 0

Good evening, I am trying to apply column filtering to a dynamically created footer but when I type a letter in the text box the table says No Matching Records Found. I am wondering if the column filtering isnt working because the footer is dynamically created and the text box cannot see the contents of the table.

Here is a link: http://live.datatables.net/xomucosu/1/edit?html,js,output

Please let me know what I am doing wrong.
Thanks in advance.

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 20,275Questions: 26Answers: 4,765

    What is your goal with the search? The best way to handle custom column searching, especially if you are wanting an OR type search, is to create a search plugin.

    Kevin

  • dt_userdt_user Posts: 51Questions: 16Answers: 0

    I want to do column filtering like in this link : https://datatables.net/examples/api/multi_filter.html.

    The only difference is that I am using a dynamically created footer.

  • kthorngrenkthorngren Posts: 20,275Questions: 26Answers: 4,765
    edited October 2019 Answer ✓

    The only difference is that I am using a dynamically created footer.

    The footer isn't the problem.

    I want to do column filtering like in this link

    What you are doing is different. You have one input and it looks like you want to search all the columns with the value of that one input. Is that the case?

    Take a look at this updated example. I have it set to only search column 1. Search for developer or something else in that column. It works.

    Now look at this example. I changed it to search column 1 and 2. You will see it is performing an AND search of the columns. In rows 2 and 3 there is Bradley Greer and Brenden Wagner. If you type s Bradley is filtered out since there is no s in the office column but Brenden remains because there is an s in both columns.

    Please describe what you want to achieve so we can help guide you to a solution.

    Kevin

  • dt_userdt_user Posts: 51Questions: 16Answers: 0

    Thank you the updated example is the exact thing I wanted at that time.
    Now I have something else similar to this discussion. I dynamically created another datatable and I added the footer to each column because I want to implement individual column filtering.
    I am having problems actually perfecting the column filtering code. The most I can get is the first column filter working.

    Here is a link to an example code showing what I am experiencing: http://live.datatables.net/figuzaco/1/edit?html,js,console,output

    Please let me know where I am going wrong.
    Thank you.

  • colincolin Posts: 15,142Questions: 1Answers: 2,586

    You're always calling table.column(), which as you aren't specifying a column, will always default to the first. Take a look at how it's done in this example.

    Colin

  • dt_userdt_user Posts: 51Questions: 16Answers: 0

    I tried following the example you linked to before asking in this forum but it still did not work for me.
    I don’t think I need to specify a column since I want the search to work for all columns.

  • kthorngrenkthorngren Posts: 20,275Questions: 26Answers: 4,765

    I don’t think I need to specify a column since I want the search to work for all columns.

    As Colin says when using column() without specifying the column it will use the default. The default will be column 0.

    The first problem with your example is you need to create the footer before initializing Datatables. This way Datatables will know about the footer.

    The second problem is you should use the code provided in the example to properly select the column to search based on the input used. Here is the updated working example:
    http://live.datatables.net/figuzaco/5/edit

    Kevin

  • dt_userdt_user Posts: 51Questions: 16Answers: 0

    Thank you so much ?.
    Does this line ( that.search() !== this.value ) in the if statement mean - If the word typed by the user is not identical to the values in each column.
    I am trying to figure out what this conditional statement means.
    Please let me know.
    Thank you.

  • kthorngrenkthorngren Posts: 20,275Questions: 26Answers: 4,765

    A good way to explain it is to use console.log statements.
    http://live.datatables.net/figuzaco/7/edit

    Essentially ( that.search() !== this.value ) compares the current column search term with what the input has. If they are both the same it doesn't perform another search. that is the column, defined in the `every() loop, that the event is attached to.

    To see this type t in the Position column. Then type e so the input has te. Then hit enter. When hitting enter they are both the same so no additional search is executed for the same search term.

    Kevin

This discussion has been closed.