Filtering buttons

Filtering buttons

Chris230291Chris230291 Posts: 34Questions: 10Answers: 1

Hello. I am able to filter text boxes and check boxes using

        /* Create an array with the values of all the checkboxes in a column */
        $.fn.dataTable.ext.order['dom-checkbox'] = function (settings, col) {
            return this.api().column(col, { order: 'index' }).nodes().map(function (td, i) {
                return $('input', td).prop('checked') ? '1' : '0';
            });
        }

        /* Create an array with the values of all the input boxes in a column */
        $.fn.dataTable.ext.order['dom-text'] = function (settings, col) {
            return this.api().column(col, { order: 'index' }).nodes().map(function (td, i) {
                return $('input', td).val();
            });
        }

And

                "columns": [
                    { "width": "1%", "orderDataType": "dom-checkbox" },
                    { "width": "20%" },
                    { "width": "20%", "orderDataType": "dom-text", type: 'string' },
                    { "width": "20%" },
                    { "width": "20%", "orderDataType": "dom-text", type: 'string' },
                    { "width": "1%" }
                ],

I tried using the same method for columns that contain buttons but it doesnt work.

Here is my buttons

<input type="button" class="myButton" value="{{ i['name'] }}" onclick="select(this)" data-link="{{ i['link'] }}">

Is it possible to search the value of them?

Thanks,
Chris

Answers

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

    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

  • Chris230291Chris230291 Posts: 34Questions: 10Answers: 1

    Thanks for the reply. Thats neat. Here is what I came up with http://live.datatables.net/husuwace/1/edit?html,js,output

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

    You could do something like this: http://live.datatables.net/husuwace/3/edit

    Colin

  • Chris230291Chris230291 Posts: 34Questions: 10Answers: 1

    Sorry I'm not sure why it wasn't working before and no idea why I included that other javascript. I misunderstood the docs. It seems this is all I need to have sortable columns with buttons and text fields...
    http://live.datatables.net/husuwace/5/edit?html,js,output

  • Chris230291Chris230291 Posts: 34Questions: 10Answers: 1

    Actually I take that back. Those other scripts are needed else I cant use 'orderFixed'.

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

    I'm getting muddled on what you're after. In the example I posted it was searching on the value of the button that was clicked. If that's not what you're after, can you expand more please, as that was what you asked for : "Is it possible to search the value of them?"

    Colin

  • Chris230291Chris230291 Posts: 34Questions: 10Answers: 1

    Sorry for my bad explanation.

    What I wanted was to be able to sort columns that contain buttons with text by clicking on the column head. For whatever reason that wasn't working for me until now.

    I thought the script I was adding above the main table script was required for column sorting to work on any columns that don't have regular text.

    But it seems that is only sometimes required? if you look at the following example, all columns can be sorted. But take away the script above the main table script, and the checkbox column stops working.

    http://live.datatables.net/husuwace/7/edit?html,js,output

    Why does the checkbox column need the script but the others do not?

  • kthorngrenkthorngren Posts: 21,330Questions: 26Answers: 4,951
    edited October 2021

    The others do need the script. Its ordering based on the original data. To see the problem change Paris to xParis and you will see the order is now incorrect. Try the same with this updated example with the dom-text plugin added:
    http://live.datatables.net/husuwace/8/edit

    Kevin

  • Chris230291Chris230291 Posts: 34Questions: 10Answers: 1

    Yes you are correct thank you. I wonder why checkboxes don't work at all without it though.

  • kthorngrenkthorngren Posts: 21,330Questions: 26Answers: 4,951
    edited October 2021

    The plugin is returning this:

    return $('input', td).prop('checked') ? '1' : '0';
    

    If the checkbox is checked its returning 1 else 0. The sorting is taking place on the 1 or 0 not the checkbox.

    Kevin

  • Chris230291Chris230291 Posts: 34Questions: 10Answers: 1

    OK thanks

Sign In or Register to comment.