5

I would like to add a checkbox or span to a header of datatables table. I don't want to add it in the Html, I want that to do that from javascript at the initialization. Please suggest me.

1
  • What you tried. Show your code. Commented Jan 4, 2013 at 14:41

3 Answers 3

6

Well I did not want to change the html, it's not that a big a change I had to do, just had to add some html at the initialization.

    nTable = $('#tblExample').dataTable({
        "bJqueryUI": true,
        "bDestroy":true,
        "bPaginate": false,
        "bSortable": false,
        "aaData":testData,
        "aoColumns": [

                    {   "sTitle": "<input type='checkbox'></input>","mDataProp": null, "sWidth": "20px", "sDefaultContent": "<input type='checkbox' ></input>", "bSortable": false},
                    {   "mDataProp": "Year"},
                    {   "mDataProp": "Month"},
                    {   "mDataProp": "Savings"}

        ]
    });
Sign up to request clarification or add additional context in comments.

Comments

0

Try this:

<table id="myTable">
<thead>
  <tr>
    <th>
      <div>
        <input id="checkbox1" type="checkbox"/>
      </div>
    </th>
  </tr>
</thead>
</table>

I just now got it your issue. I think this post solves this.

1 Comment

I don't want to change the html as mentioned in the question.
0

This is old, but I am going to add this statement here for those looking in the future. {"mData":"LineItem_nbr",
"mRender": function (data,type,full) { data contains the value for the mData return ''; }, }

Change LineItem_nbr to the autoID or what ever you are using to identify the record.

This will place a checkbox in the row you add this line, and it is usable looking up by the id, or you can use the class in there for a jQuery grab on multiple items.

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.