Datatables data-order data-search not working correctly on search with knockout js binding

277 views
Skip to first unread message

Aniket Bhadane

unread,
Aug 11, 2015, 7:32:17 AM8/11/15
to KnockoutJS
I have table whose tbody is binded with a knockout js observable array:


   
<table id="tableExt">
       
<thead>
           
<tr>
               
<th>Extended Property Id</th>
               
<th>Extended Property Name</th>
               
<th>Default Value</th>
           
</tr>
       
</thead>
       
<tfoot>
           
<tr>
               
<th>Extended Property Id</th>
               
<th>Extended Property Name</th>
               
<th>Default Value</th>
           
</tr>
       
</tfoot>
       
<tbody data-bind="foreach: TestCaseExtendedProperties">
           
<tr>
               
<td data-bind="text: TestCaseExtendedPropertyId"></td>
               
<td data-bind="attr: {'data-search': TestCaseExtendedPropertyName()}, attr: {'data-order': TestCaseExtendedPropertyName()}"><input data-bind="attr: {value: TestCaseExtendedPropertyName}" /></td>                        
               
<td data-bind="attr: {'data-search': DefaultValue()}, attr: {'data-order': DefaultValue()}"><input data-bind="attr: {value: DefaultValue}" /></td>
           
</tr>
       
</tbody>
   
</table>


I have applied Datatable to the table as:

   
// Setup - add a text input to each footer cell
    $
('#tableExt tfoot th').each(function () {
       
var title = $('#tableExt thead th').eq($(this).index()).text();
        $
(this).html('<input type="text" placeholder="Search ' + title + '" />');
   
});
   
   
var table = $('#tableExt').DataTable( {
               
"columnDefs": [{
                   
"targets": 0,
                   
"visible": true,
               
}]
           
});
   
   
// Apply the search
    table
.dt.columns().every(function () {
       
var that = this;
   
        $
('input', this.footer()).on('keyup change', function () {
            that
               
.search(this.value)
               
.draw();
       
});
   
});



I have added search input box to each column to do individual column searching

And  applied data-search and data-order to two fields:

1) TestCaseExtendedPropertyName in Extended Property Name column

2) DefaultValue in Default Value column

Searching values in [Extended Property Name] column in datatables works fine, but searching values in [Default Value] column does not work and says No matching records found

Where am I going wrong?

Reply all
Reply to author
Forward
0 new messages