DataTables - push - read Html.CheckBoxFor value

DataTables - push - read Html.CheckBoxFor value

TimothyVTimothyV Posts: 34Questions: 7Answers: 0

Hi, can someone please assist me in reading the checked value of a CheckBoxFor when iterating through the rows? I would like to know the value so then I can apply it against a filter to determine whether to show or not show the row.

$.fn.dataTable.ext.search.push(
    function (settings, data, dataIndex) {
        alert(data[0]); //returns nothing and need checked value

html...
<td>@Html.CheckBoxFor(modelItem => item.CheckBox)</td>

This question has an accepted answers - jump to answer

Answers

  • colincolin Posts: 15,237Questions: 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

  • TimothyVTimothyV Posts: 34Questions: 7Answers: 0

    Thanks Colin, you are correct. I have posted the sample at https://jsfiddle.net/TimothyV/e5vdwco0/3/

  • kthorngrenkthorngren Posts: 21,172Questions: 26Answers: 4,922
    Answer ✓

    I'm not familiar with what @Html.CheckBox("checked", false) will result in. However if you are trying to access the row node instead of data you can use the technique Allan mentions in this thread to get the row's node. Then use can evaluate the checkbox. I updated your example to show this:
    https://jsfiddle.net/Lqdgzhfm/1/

    Not sure if this is what you are looking for.

    Kevin

  • TimothyVTimothyV Posts: 34Questions: 7Answers: 0

    Kevin, thank you so much! Your solution works perfectly in the larger project I was trying to implement it for. I truly appreciate your expertise and willingness to look into this.

    https://datatables.net/ rocks!

    Have a great day and stay healthy.

    Timothy

This discussion has been closed.