How can I add a button with knockout binding to each row in a table

How can I add a button with knockout binding to each row in a table

bonesjusticebonesjustice Posts: 1Questions: 1Answers: 0
edited June 2014 in Free community support

I've implemented datatables with knockout as per the example at http://datatables.net/dev/knockout/, but I often need to add a button in one of the columns and bind it to some function defined in my knockout model (e.g., if the table is showing a list of contacts, I would put an edit button in the last column.). With knockout I could add the following to my table:

<td><button data-bind="click: $parent.someFunction()">Edit</button></td>

But in the example there is no knockout syntax in the html because of the way rows are added directly to the DataTables object.

I managed to add a button in the columns, but I don't know how to get it to bind to "someFunction":

    columns: [
        { data: 'Name()' },
        { data: 'Type()' },
        {
            render: function (obj) {
                return '<button data-bind="click: someFunction"></button>'; /* this doesn't work */
            },
            orderable: false, 
            searchable:false
        }

Answers

This discussion has been closed.