Having issue with legacy data tables specifically fnfilter with multiple columns

Having issue with legacy data tables specifically fnfilter with multiple columns

krubinkrubin Posts: 4Questions: 1Answers: 0
edited March 2019 in Free community support

Hello,

I modified a Javascript to attempt to filter on 2 different criteria. The first fnfilter worked previously. I added the second to fnfilter on the
line below it to filter on the eighth column in a table.

My ViewSLTable had an 8th column added to it in my mvc razor script. I put a value of either "enabled" or "disabled"
in it. I had hoped that it would be my second search criteria. Any suggestions would be greatly appreciated.

Thank you,
Ken

JavaScript
$(document).ready(function () {
    var table = $('.ViewSLTable').DataTable({
        "search": {
            "regex": false
        },
        "columnDefs": [
            {
                "targets": [4],
                "visible": false,
            },
            {
                "targets": [5],
                "visible": false
            },
            {
                "targets": [6],
                "visible": false
            },
            {
                "targets": [7],
                "visible": false
            }
        ]
    });

    
    $('.UserDropDown').change(function () {
        oTable = $('.ViewSLTable').dataTable();
        oTable.fnFilter($(this).val());
        oTable.fnFilter("enabled", 7);
    });  
});
Additions to Razor .cshtml
Change to header section:
            <th>
                @Html.TextBox("enabled",null, new {@class = "form-control" })

            </th>

Change to body. Did not show code to insert value: Values will be :disabled or enabled.
<td>
...
@Html.HiddenFor(model => enabledString, enabledString);

</td>

Answers

  • colincolin Posts: 15,240Questions: 1Answers: 2,599

    Hi @krubin ,

    We're happy to take a look, but as per the forum rules, please link to a test case - a test case that replicates the issue will ensure you'll get a quick and accurate response. 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

  • krubinkrubin Posts: 4Questions: 1Answers: 0

    Hi Support/Colin,

    I have created a milestone and shared it. Hopefully you can see it at: http://live.datatables.net/nazedexi/1/edit.

    Our jquery.dataTables.js file shows version 1.10.2.

    Using your environment, I can see the results that I have targeted. The goal was to use fnfilter on multiple columns. This is where one column is related to a drop down box and the other column has a fixed value.

    However in my environment, there are some differences which I cannot recreate in your environment.

    • I am using a class for the dropdown and the table, which is created by Razor:

    Dropdown
    @Html.DropDownListFor(model => model.mymodel.UserName, new SelectList(MySelectList.GroupBy(o => o.Value).Select(c => c.FirstOrDefault()), "Value", "Text"), new { @class = "form-control UserDropDown" })

    Table Class name

    <

    table class="UserTable display" width="100%" cellspacing="0">

    Field where I filter against using second fnfilter statement
    @Html.TextBox("enabled",null, new {@class = "form-control" })

    My javascript using fnfilter script worked fine previously referencing the razor code shown above, but when I tried to add the second filter oTable.fnFilter("enabled", 3) and the new textbox shown above the fnfilter had no effect.

    I hope this is sufficient information for support and greatly appreciate any assistance!
    Thank you,
    Ken

  • krubinkrubin Posts: 4Questions: 1Answers: 0
  • allanallan Posts: 63,482Questions: 1Answers: 10,467 Site admin

    Hi Ken,

    The first thing to do is to update to the latest version. 1.10.2 is really quite old now - 1.10.19 is the current release and I've got a feeling it fixed something about the legacy fnFilter method way back around .3 or .4. Certainly that would be the starting point.

    Allan

  • krubinkrubin Posts: 4Questions: 1Answers: 0

    Thank you Allan! I will discuss this with my company's management.

This discussion has been closed.