How can I add a column of checkboxes to a dynamically generated table?

How can I add a column of checkboxes to a dynamically generated table?

grahamfgrahamf Posts: 2Questions: 1Answers: 0

I'm sure this must be a common requirement but I can't seem to be able to figure out how to add a column of checkboxes to a table that is generated from data held in a back-end database table....

HTML:

Time Column 1 Column 2
Time Column1 Column2

JScript:

            var table = $('#mytable').DataTable( {
                "ajax": {
                    url: '/cgi-bin/supp_get_data_backend.plx',
                    data: {
                        "CIs": CIs
                    }
                },
                "columns": [
                    { "data": "firstoccurrence" },
                    { "data": "col1" },
                    { "data": "col2" }
                ]
                            });

What do I need to include in the JScript to add a column of checkboxes? I'm using the latest version of datatables: 1.10.0

Thanks.

Answers

  • grahamfgrahamf Posts: 2Questions: 1Answers: 0

    Oh well, I suppose I'll have to answer this myself then...... :-)

    In my HTML I added an extra div after the <tr> as follows.....

    <tr>
    <div class="mycheckbox">
    <th>CB</th>
    </div>
    ......

    In the JS I added this to the columns section.......

                    "columns": [
                        { "data": null, className: "mycheckbox", defaultContent:'<input type="checkbox",value="">'},                    
                        { "data": "firstoccurrence" },
                        { "data": "col1" },
                        { "data": "col2" }
                    ]
    

    Works lovely after that.......perhaps the manual could be updated with some additional "real life" examples?

This discussion has been closed.