javascript - Bootstrap-表自定义搜索

标签 javascript jquery bootstrap-table

我有一个看起来像这样的自定义搜索,但我该如何使用它 在所有列中而不仅仅是 colName 列?

https://live.bootstrap-table.com/code/janttila/5112

function customSearch(data, text) {
    return data.filter(function (row) {

        return  row.colName.toLowerCase().replace(/\s/g, "").indexOf(text.toLowerCase().replace(/\s/g, "")) > -1

    })
  }

最佳答案

您可以遍历所有列。但也许提供更多代码来获得有效的解决方案。我不知道你的数据对象到底是什么样的。

//编辑: 关于您的数据结构,该函数将如下所示:

    function customSearch(data, text) {
return data.filter(function (row) {
 
  for (let items of Object.values(row)){
    if (items.toString().toLowerCase().replace(/\s/g, "").indexOf(text.toLowerCase().replace(/\s/g, "")) > -1){
    return true
  }
  }
})
}

我们迭代行中的所有评估值并检查是否有任何适合搜索文本。但请注意,您的数据集还有您未显示的条目数量。此内容也将包含在搜索中

//编辑2:

function customSearch(data, text) {
return data.filter(function (row) {
 searchFor = ["id", "name", "price"]
  
 for (elem of Object.keys(row)){
   if (searchFor.indexOf(elem) < 0) {
     delete row[elem]
   }
 }

  for (let items of Object.values(row)){
    if (items.toString().toLowerCase().replace(/\s/g, "").indexOf(text.toLowerCase().replace(/\s/g, "")) > -1){
    return true
  }
  }
})
}

关于javascript - Bootstrap-表自定义搜索,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64370019/

相关文章:

javascript - Angular 将数据从 Controller 传递到状态

javascript - 使用ffmpeg javascript从wav音频文件转换为pcm音频文件

javascript - 在 JSON 数组中搜索字符串并检索包含该字符串作为值的对象

jquery - Bootstrap-table 动态改变表格高度

css - 如何在引导表中设置单选按钮或复选框的样式?

javascript - Twitter Bootstrap 表格可编辑的 json 数据

c# - 为什么我的 PDF 生成过程会锁定我站点中的其他 ajax 过程?

javascript - 这个 ie 检查是如何工作的?

javascript - 我如何连续遍历所有 <td> 标签并在单击按钮时获取值

javascript - w2ui:错误:无法添加没有 recid 的记录。 (对象:网格)