2

In jQuery datatable, how to bind a checkbox column dynamically, when binding server data?

My code:

oTable = $("#tblPreProcess").dataTable({
            bProcessing: true,
            bLengthChange: false,
            bFilter: true,
            sAjaxSource: '@Url.Action("FetchPreprocessOrders", "Admin")',
            aoColumns: [
               { sTitle: "Order No", bSortable: false ,bSearchable: true},
                { sTitle: "Vol.Weight", bSortable: false },
                { sTitle: "Content", bSortable: false, },               
                 { sTitle: "Bag Number", bSortable: false }                               
            ]               

        });

In the code given above, how do I add a checkbox column before 'Order No' column.

2

1 Answer 1

2

you can do this like below code:

    oTable = $("#tblPreProcess").dataTable({
            bProcessing: true,
            bLengthChange: false,
            bFilter: true,
            sAjaxSource: '@Url.Action("FetchPreprocessOrders", "Admin")',
            aoColumns: [
               { sTitle: "Select", bSortable: false ,
                 mRender: function (data, type, full)
                 {
                    return '<input type="checkbox" class="selector" data-id="'+ data +'">'
                 },
               { sTitle: "Order No", bSortable: false ,bSearchable: true},
               { sTitle: "Vol.Weight", bSortable: false },
               { sTitle: "Content", bSortable: false, },               
                { sTitle: "Bag Number", bSortable: false }                               
            ]               

        });
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.