One Column Filtering in Header

One Column Filtering in Header

robovrobov Posts: 31Questions: 5Answers: 0

I would like to add a column filtering option next to the search box. This column is autofilled with one of the columns from the table. Any suggestion how to do this ?

Answers

  • rhinorhino Posts: 80Questions: 2Answers: 17

    Is it a dropdown select that you are autofilling?

  • robovrobov Posts: 31Questions: 5Answers: 0

    rhino, yes that is what I am trying to do. Made it work with the sample in the footer. But I need it outside the footer, and only 1 selected column

  • rhinorhino Posts: 80Questions: 2Answers: 17
  • robovrobov Posts: 31Questions: 5Answers: 0

    Thank looks amazing... !!
    but the filtering does not work yet or am I missing something

  • rhinorhino Posts: 80Questions: 2Answers: 17

    Um. Refresh and see if it works. I made some changes after I posted.

    If that doesn't work, are you using IE? I've noticed that input doesn't work correctly on live.datatables.net when using IE :(

  • rhinorhino Posts: 80Questions: 2Answers: 17
    Answer ✓

    Heh, sorry about that. Try this one!

  • robovrobov Posts: 31Questions: 5Answers: 0

    AMAZING !!
    Exactly.... thank you...
    Just one more (maybe stupid) question. When I implemented this, and used my ajax source it no longer seemed to fill the dropdown.

  • rhinorhino Posts: 80Questions: 2Answers: 17

    My first idea would be to place the creation of the dropdown into the initComplete callback option. Something along the lines of:

    var theTable = $('#example').DataTable( {
      // initialization options here
      initComplete: function(settings, json) {
        //use theTable var to create the dropdown here
      }
    });
    
  • rhinorhino Posts: 80Questions: 2Answers: 17

    On the other hand, I don't know if theTable would be accessible at that point in the code, so you may have to use the settings or json object to get the column data and build the dropdown.

  • robovrobov Posts: 31Questions: 5Answers: 0

    I understand your first reply...
    But the second part ", so you may have to use the settings or json object to get the column data and build the dropdown." I do not understand

  • robovrobov Posts: 31Questions: 5Answers: 0

    btw, placing the code in the initComplete does work... but I am not sure for how long (the data can be)

  • rhinorhino Posts: 80Questions: 2Answers: 17
    Answer ✓
  • daniel_rdaniel_r Posts: 460Questions: 4Answers: 67
    Answer ✓

    you can also use my yadcf for the column filtering http://yadcf-showcase.appspot.com/DOM_source_chosen.html

  • robovrobov Posts: 31Questions: 5Answers: 0

    @daniel_r.... GREAT plugin !! thank you for this tip. Does it also support date filtering ? (ie today, last 7 days, last month ) ?

  • robovrobov Posts: 31Questions: 5Answers: 0

    @rhino... SUPER... thank you sooo much !

  • daniel_rdaniel_r Posts: 460Questions: 4Answers: 67

    @robov, yadcf got 8 different types of filter types and lots of lots of different customization's/properties you can take a look at the filter_type: "range_date", in the showcase: http://yadcf-showcase.appspot.com/DOM_source.html

  • robovrobov Posts: 31Questions: 5Answers: 0

    Excellent, thank you daniel_r. Looks like an amazing plugin. Can I suggest to include an extra filter based on dates (show only from today, show only this week, show only this month, show only last 3 months, show only this year

  • daniel_rdaniel_r Posts: 460Questions: 4Answers: 67
    edited July 2014 Answer ✓

    I can enhance the range_date, you will have to provide array of objects "[{vale: 1, label: Today}, {vale: 2, label: Last week}, ... etc] and custom function that will accept two parameters (type, date_val) where the type will be one of the values from the array of obj and the date_val will be one of the date in the relevant column - this "custom function" will be executed for each row in table and the date_val will be tested against that function which in turn will return true / falsem so instead of tow date inputs you will have a select menu with values from that array of objects you provide yourself and each time you select a value from the select your "custom function" will be executed for each row (for relevant column), if you want this feature open a new issue on yadcf project page (will take some time) https://github.com/vedmack/yadcf/issues?milestone=1&state=open


    Actually it wont be an enhancement of range_date , instead it will be a new filter type that will allow the use of custom filtering function (will be good for date and any other type of inputs too)

  • robovrobov Posts: 31Questions: 5Answers: 0

    Thanks... another option would be to have hidden fields that are dynamically filled with the start and end date. So I select a external dropdown, this fills the hidden date_Start and date finish fields and virtually presses filter.
    That might be even easier... but I do not know how yet

  • daniel_rdaniel_r Posts: 460Questions: 4Answers: 67

    the other option will be harder to maintain (for you) because you will have to create new dates for your hidden fields each time, because the last month dates as they are today will be different tomorrow and the day after tomorrow. IMO the "custom filtering function" is more powerful and useful :)

  • robovrobov Posts: 31Questions: 5Answers: 0

    The hidden fields option would ofcourse be some js to calculate the dates based on today(). hahah... Not intending to maintain that everyday

    IMO the "custom filtering function" is more powerful ==> Agree

This discussion has been closed.