0

I have a JQuery Datatable with a checkbox in one of the column headings:

<table id="vehTbl" class="table table-striped table-bordered">
  <thead>
    <tr>
        ...
        <th>
            <input type="checkbox" id="someId" onchange="TickAllBoxes()" />
            Publish
        </th>
    </tr>
  </thead>
</table>

My datatable is initialised like this:

var table = $("#vehTbl").dataTable(
    {
        ...
        "aoColumns":
        [
            ...
            {
                "mDataProp": "SomeName",
                "fnRender": somefunction,
                "bUseRendered": false
            },
            ...
        ]
    });

So this column is sortable. Now I need to prevent the sort event from being fired when checkbox is clicked (and TickAllBoxes is fired as a result). The sorting should work on the column otherwise.

What could potentially work is to bind a handler to "sort" event of the table and prevent default if caller is "someId" checkbox. I haven't had success in doing so, though.

Any ideas?

1 Answer 1

1

Try to add in this script after your dataTable is initialised, and see?

var table = $("#vehTbl").dataTable(
{
    ...
    "aoColumns":
    [
        ...
        {
            "mDataProp": "SomeName",
            "fnRender": somefunction,
            "bUseRendered": false
        },
        ...
    ]
});
// add in this
$('input[type=checkbox]').click(function(event){event.stopPropagation()});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.