Filtering buttons

Filtering buttons

Chris230291Chris230291 Posts: 25Questions: 7Answers: 0

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: 12,911Questions: 0Answers: 2,200

    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: 25Questions: 7Answers: 0

    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: 12,911Questions: 0Answers: 2,200

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

    Colin

  • Chris230291Chris230291 Posts: 25Questions: 7Answers: 0

    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: 25Questions: 7Answers: 0

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

  • colincolin Posts: 12,911Questions: 0Answers: 2,200

    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: 25Questions: 7Answers: 0

    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: 14,124Questions: 25Answers: 3,331
    edited October 5

    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: 25Questions: 7Answers: 0

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

  • kthorngrenkthorngren Posts: 14,124Questions: 25Answers: 3,331
    edited October 6

    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: 25Questions: 7Answers: 0

    OK thanks

Sign In or Register to comment.