首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用可数据筛选表中选择的值

如何使用可数据筛选表中选择的值
EN

Stack Overflow用户
提问于 2019-10-16 12:33:06
回答 1查看 629关注 0票数 2

*我的小提琴:http://jsfiddle.net/6e9r2js1/

这是某人的参考工作链接:http://jsfiddle.net/8c96qx2z/

这是某人的参考工作链接:http://jsfiddle.net/a3o3yqkw/

这是我的密码:

代码语言:javascript
复制
<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>

在类型上没有搜索..。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-10-16 13:31:48

我从这个堆叠溢出的答案中找到了一个小提琴url:https://stackoverflow.com/a/27860934/540195

我更新了小提琴(http://jsfiddle.net/s2gbafuz/),现在它运转良好,

您可以检查分叉工作小提琴链接: http://jsfiddle.net/amitmondal/zc5a3eox/1/

代码语言:javascript
复制
$.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();
});

,如果您需要进一步的帮助,请随时通知我。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/58413435

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档