John
John

Reputation: 17491

Knockout + jQuery DataTables Search Filter

I have a scenario where I have a list of javascript objects managed by knockout, where I'm wanting to let jQuery datatables handle displaying the list to the user (for consistency, since I'm using datatables to display static content elsewhere).

So I have something like so: http://jsfiddle.net/MLfcs/

Everything is working great outside of the search feature: It is not picking up the values of the inputs. If you try the fiddle and search for the contents of any of the inputs, all of the rows will be filtered out.

Is there an easy way to create a custom filter to handle this? Or a custom knockout binding? I'd rather not have to resort to doing something like this:

from:

 <td><input type="text" data-bind="value: partA" /></td>

to:

 <td><input type="text" data-bind="value: partA" /><span data-bind="text: partA" style="display: none" /></td>

I know the datatables search should be working correctly for inputs, but I just wasn't sure of what knockout is missing in the databinding to get that to work correctly.

Thanks!

Upvotes: 1

Views: 2245

Answers (1)

BillPull
BillPull

Reputation: 7013

Try binding the value attribute with the actual attr binding as well.

<td><input type="text" data-bind="value: item.partA, attr: {'value': item.partA}" /></td>

http://jsfiddle.net/billpull/ZBCvD/1/

dont think there is anyway to do this with just the value binding.

Upvotes: 1

Related Questions