2

*my jsfiddle: http://jsfiddle.net/6e9r2js1/

this is someone's reference working link: http://jsfiddle.net/8c96qx2z/

this is someone's reference working link: http://jsfiddle.net/a3o3yqkw/

this is my code:

<table id="tabledetail">
<thead>
  <tr>
     <th>S.#</th>
     <th>Name</th>
     <th>Type</th>
   </tr>
</thead>
<tbody>
   <tr>
      <td>1</td>
      <td><input type="text" id="name_1" name="myName[]" value="Ben"></td>
      <td>
          <select class="form-control" id="type_1" name="myType[]">
              <option value="0" selected>No</option>
              <option value="1">Yes</option>
          </select>
      </td>
   </tr>
   <tr>
       <td>2</td>
      <td><input type="text" id="name_2" name="myName[]" value="Dan"></td>
      <td>
          <select class="form-control" id="type_2" name="myType[]">
              <option value="0">No</option>
              <option value="1" selected>Yes</option>
          </select>
      </td>
   </tr>
</tbody>
</table>

<script>
    var table = $('#tabledetail').DataTable({
        'orderCellsTop': true,
        'fixedHeader'  : true,
        'paging'       : true,
        'lengthChange' : true,
        'searching'    : true,
        'ordering'     : true,
        'info'         : true,
        'autoWidth'    : true,
        'columnDefs'   : [{ "type": "html-input", "targets": ['_all'] }]
    });
</script>

On type its not searching...

5
  • i check your jsfiddle code, which looks fine to me Commented Oct 16, 2019 at 12:35
  • thats someone else jsfiddle i want to implement it in my code.. Commented Oct 16, 2019 at 12:36
  • here i tried this code but doesnt work datatables.net/forums/discussion/54017/… Commented Oct 16, 2019 at 12:37
  • create column value dynamically then assign function to select Commented Oct 16, 2019 at 13:03
  • column select's selected value is already coming from database dynamically, i want my search filter apply only on selected value of select and input and simple text in td Commented Oct 16, 2019 at 13:11

1 Answer 1

0

I have found a fiddle url from this stackoverflow answer: https://stackoverflow.com/a/27860934/540195

I have updated that fiddle (http://jsfiddle.net/s2gbafuz/) and now it's working fine,

You can check the forked working fiddle link: http://jsfiddle.net/amitmondal/zc5a3eox/1/

$.fn.dataTableExt.ofnSearch['html-input'] = function(value) {
   return $(value).val();
};

var table = $("#example").DataTable({
    columnDefs: [
       { "type": "html-input", "targets": [1, 2, 3] }
    ] 
});

$("#example td input").on('change', function() {
    var $td = $(this).parent();
    $td.find('input').attr('value', this.value);
    table.cell($td).invalidate().draw();
});
$("#example td select").on('change', function() {
    var $td = $(this).parent();
    var value = this.value;
    $td.find('option').each(function(i, o) {
      $(o).removeAttr('selected');
      if ($(o).val() == value) {
      	 $(o).attr('selected', true);
         $(o).prop('selected', true);
      } 
    })
    table.cell($td).invalidate().draw();
});

Please don't hesitate to let me know if you need any further help.

Sign up to request clarification or add additional context in comments.

5 Comments

Hi, can u please check my fiddle jsfiddle.net/6e9r2js1 i implemented ur code there but doesnt work
I didn't see my code in your fiddle, would you please check again?
Yes, you are right :) , I mentioned that fiddle url and now going to share the answer link also.
Kindly check this fiddle which I am tying to fix jsfiddle.net/6e9r2js1/2 your given fiddle I have already mentioned in question from searching the same stackoverflow anser which is working, i want my fiddle work, thanks.
I managed to fix a bit see this fiddle jsfiddle.net/k7ymhgrs I think issue is with targets where column number need to be told where to search, as I added 1 more column it started to work

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.