Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/371.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/85.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript jquery数据表修改搜索以不筛选所选行_Javascript_Jquery_Datatables - Fatal编程技术网

Javascript jquery数据表修改搜索以不筛选所选行

Javascript jquery数据表修改搜索以不筛选所选行,javascript,jquery,datatables,Javascript,Jquery,Datatables,这是小提琴 我有一个jquery数据表,每行上都有一个复选框。我希望,如果选中了行上的复选框,那么在使用搜索框时,所选行不会被隐藏。例如,如果在搜索框为空的情况下选择John,然后我在搜索框中键入Fred,John在数据表中仍然可见,因为他被选中了。因此,searchbox筛选器不适用于选定的行 下面是javascript function employee(id, firstName, lastName, dept, active) { var self = this; this.id

这是小提琴

我有一个jquery数据表,每行上都有一个复选框。我希望,如果选中了行上的复选框,那么在使用搜索框时,所选行不会被隐藏。例如,如果在搜索框为空的情况下选择John,然后我在搜索框中键入Fred,John在数据表中仍然可见,因为他被选中了。因此,searchbox筛选器不适用于选定的行

下面是javascript

function employee(id, firstName, lastName, dept, active) {
  var self = this;
  this.id = id;
  this.firstName = firstName;
  this.lastName = lastName;
  this.dept = dept;
  this.active = active;
}

function model() {
  var self = this;
  this.employees = [];
}

var mymodel = new model();

$(document).ready(function() {
  mymodel.employees.push(new employee('1', 'Clara', 'Dellinger', 'IT', false));
  mymodel.employees.push(new employee('2', 'John', 'Smith', 'HR', false));
  mymodel.employees.push(new employee('3', 'Fred', 'Jones', 'Finance', false));
  mymodel.employees.push(new employee('4', 'Mary', 'Jans', 'Finance', false));
  mymodel.employees.push(new employee('5', 'Bob', 'Jones', 'IT', false));
  mymodel.employees.push(new employee('6', 'Fred', 'Thebes', 'HR', false));
  mymodel.employees.push(new employee('7', 'Sally', 'Jane', 'HR', false));
  mymodel.employees.push(new employee('8', 'Patrick', 'Roberts', 'HR', false));
  mymodel.employees.push(new employee('9', 'Lisa', 'Myers', 'Lab', false));
  mymodel.employees.push(new employee('10', 'Roscoe', 'Coletrain', 'Security', false));
  var table = $('#mytable').DataTable({
    data: mymodel.employees,
    columns: [{
      data: 'active',
      render: function(data, type, row) {
        if (type === 'display') {
          return '<input type="checkbox" class="editor-active">';
        }
        return data;
      },
      className: "dt-body-center"
    }, {
      data: 'id'
    }, {
      data: 'firstName'
    }, {
      data: 'lastName'
    }, {
      data: 'dept'
    }],
    rowCallback: function(row, data) {
      // Set the checked state of the checkbox in the table
      $('input.editor-active', row).prop('checked', data.active);
    }
  });

  $('#mytable tbody').on('click', 'input[type="checkbox"]', function(e) {
    var active = $(this).prop('checked');
    var $row = $(this).closest('tr');
    var employee = table.row($row).data();
    employee.active = active;
    console.log(employee);
    table.row($row).data(employee).draw();
  });

});
职能员工(id、姓氏、姓氏、部门、活动){
var self=这个;
this.id=id;
this.firstName=firstName;
this.lastName=lastName;
this.dept=dept;
这个.active=active;
}
函数模型(){
var self=这个;
这是1.employees=[];
}
var mymodel=新模型();
$(文档).ready(函数(){
mymodel.employees.push(新员工('1','Clara','Dellinger','IT',false));
mymodel.employees.push(新员工('2','John','Smith','HR',false));
mymodel.employees.push(新员工('3','Fred','Jones','Finance',false));
mymodel.employees.push(新员工('4','Mary','Jans','Finance',false));
mymodel.employees.push(新员工('5','Bob','Jones','IT',false));
mymodel.employees.push(新员工('6','Fred','Thebes','HR',false));
mymodel.employees.push(新员工('7','Sally','Jane','HR',false));
mymodel.employees.push(新员工('8','Patrick','Roberts','HR',false));
mymodel.employees.push(新员工('9','Lisa','Myers','Lab',false));
mymodel.employees.push(新员工('10','Roscoe','Coletrain','Security',false));
变量表=$('#mytable')。数据表({
数据:mymodel.employees,
栏目:[{
数据:“活动”,
呈现:函数(数据、类型、行){
如果(类型==‘显示’){
返回“”;
}
返回数据;
},
类名:“dt车身中心”
}, {
数据:“id”
}, {
数据:“名字”
}, {
数据:“lastName”
}, {
数据:“部门”
}],
rowCallback:函数(行、数据){
//设置表中复选框的选中状态
$('input.editor active',row.prop('checked',data.active));
}
});
$('#mytable tbody')。在('click','input[type=“checkbox”]”上,函数(e){
var active=$(this.prop('checked');
var$row=$(this.closest('tr');
var employee=table.row($row).data();
employee.active=active;
控制台日志(员工);
table.row($row).data(employee.draw();
});
});
这是html

<table class="table" id="mytable">
  <thead>
    <tr>
      <th>Select</th>
      <th>Id</th>
      <th>First</th>
      <th>Last</th>
      <th>Dept</th>
    </tr>
  </thead>
  <tbody>
  </tbody>
</table>

挑选
身份证件
弗斯特
最后
部

你在搜索框中像这样搜索comm(,)Fred,John你不能像这样吗?我不明白你在说什么或在问什么。我试图不让searchbox对选中复选框的表行执行筛选。因此,如果选中复选框,该行将无法被过滤。好的,我现在明白了你的意思,谢谢你查找“或”逻辑搜索谢谢你,我想我已经成功了。如果你把你的评论改成答案,我可以把它改成正确的。