- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个关于 https://github.com/Dynamitable/Dynamitable 的问题.
当我尝试过滤结果时,它不会显示完全匹配的结果。例如,当我在过滤框中输入 1 时,它会带来包括 1 在内的所有值。当我尝试过滤时,是否可以使其仅显示确切的数字?
感谢您的帮助!
最佳答案
在这里我更改了库并添加了您想要的精确匹配功能。查看分数过滤器输入,我添加了一个属性 searchType="exact"它将搜索包含此属性的那些输入的完全匹配
在 this.filter 中进行了更改
this.filter = function filter(index, matches, searchType) {
if (searchType != "exact" || matches.length<=0 )
{
var regex = new RegExp(matches, 'i');
dynamitableCore.getRows().each(function () {
if(true !== regex.test(dynamitableCore.getValue(index, $(this)))) {
$(this).hide();
}
});
}else {
// added this
dynamitableCore.getRows().each(function () {
var v = dynamitableCore.getValue(index, $(this));
if(v != matches) {
$(this).hide();
}
});
}
return this;
};
!function($){ 'use strict';
$.fn.dynamitable = function(options) {
/**********************************************
* dynamitable
**********************************************/
var dynamitable = this;
/**********************************************
* dynamitableCore
**********************************************/
var dynamitableCore = new (function($dynamitable) {
/**********************************************
* dynamitableCore.getIndex($field)
*
* get the index of a field
*
* return integer
**********************************************/
this.getIndex = function($field) {
return $field.parents('tr').children('td, th').index($field);
};
/**********************************************
* dynamitableCore.getBody()
*
* get the body of the table
*
* return dom
**********************************************/
this.getBody = function() {
return $dynamitable.find('tbody');
};
/**********************************************
* dynamitableCore.getRows()
*
* get all row inside the body of the table
*
* return dom
**********************************************/
this.getRows = function() {
return this.getBody().children('tr');
};
/**********************************************
* dynamitableCore.getField(index, $row)
*
* get a field
*
* return dom
**********************************************/
this.getField = function(index, $row) {
return $row.children('td, th').eq(index);
};
/**********************************************
* dynamitableCore.getValue(index, $row)
*
* get a field value
*
* return string
**********************************************/
this.getValue = function(index, $row) {
return this.getField(index, $row).text();
};
})($(this));
/**********************************************
* dynamitable.filterList
*
* list of filter selector
*
* array of string
**********************************************/
this.filterList = [];
/**********************************************
* dynamitable.displayAll()
*
* show all <tr>
*
* return dynamitable
**********************************************/
this.displayAll = function() {
dynamitableCore.getRows().each(function() {
$(this).show();
});
return this;
};
/**********************************************
* dynamitable.filter(index, matches)
*
* hide all <tr> that doen't martch
*
* - index (integer): index of the colum to filter
* - matches (string) : string to search on the colum
*
* return dynamitable
**********************************************/
this.filter = function filter(index, matches, searchType) {
if (searchType != "exact" || matches.length<=0 )
{
var regex = new RegExp(matches, 'i');
dynamitableCore.getRows().each(function () {
if(true !== regex.test(dynamitableCore.getValue(index, $(this)))) {
$(this).hide();
}
});
}else {
dynamitableCore.getRows().each(function () {
var v = dynamitableCore.getValue(index, $(this));
if(v != matches) {
$(this).hide();
}
});
}
return this;
};
/**********************************************
* dynamitable.addFilter(selector)
*
* add filter event on element inside the table heading
*
* - selector (string) : selector of the element that trigger the event
*
* return dynamitable
**********************************************/
this.addFilter = function addFilter(selector) {
// add the selector on the filter list
dynamitable.filterList.push(selector);
// the filter
var filterAction = function() {
dynamitable.displayAll();
$(dynamitable.filterList).each(function(index, selector) {
$(dynamitable).find(selector).each(function() {
var $this = $(this);
var searchType = $this.attr("searchType"); // eg string or decimal
dynamitable.filter(dynamitableCore.getIndex($this.parent('td, th')), $this.val(), searchType);
});
});
};
// attach the filter action to the selector
$(selector).on('change keyup keydown', filterAction);
// initialization
filterAction();
return this;
};
/**********************************************
* dynamitable.addSorter(selector, order)
*
* add soter event on element inside the table heading
*
* - selector (string) : selector of the element that trigger the event
* - order (string) : sorting order [asc, desc]
*
* return dynamitable
**********************************************/
this.addSorter = function addSorter(selector, order) {
$(dynamitable).find(selector).each(function() {
var $this = $(this);
var index = dynamitableCore.getIndex($this.parent('td, th'));
$this.on('click', function() { dynamitable.sorter(index, order); });
});
return this;
};
/**********************************************
* dynamitable.sorter(index, order)
*
* - index (integer): index of the colum to sorter
* - order (string) : sorting order [asc, desc]
*
* return dynamitable
**********************************************/
this.sorter = function sorter(index, order) {
dynamitableCore.getBody().append(dynamitableCore.getRows().detach().sort(function(row_a, row_b) {
var value_a = dynamitableCore.getValue(index, $(row_a));
var value_b = dynamitableCore.getValue(index, $(row_b));
var order_desc = ('desc' === order) ? true : false;
// numeric order mode
if(value_a.replace(/[^\d-]/g, '') !== '' && value_b.replace(/[^\d-]/g, '') !== '') {
value_a = parseFloat(value_a.replace(/[^\d,.\-\+]/g, ''));
value_b = parseFloat(value_b.replace(/[^\d,.\-\+]/g, ''));
}
if(value_a === value_b) {
return 0;
}
return (value_a > value_b) ? order_desc ? 1 : -1 : order_desc ? -1 : 1;
}));
return this;
};
return this;
};
/**********************************************
* Dynamitable trigger
**********************************************/
$(document).find('.js-dynamitable').each(function(){
$(this).dynamitable()
.addFilter('.js-filter')
.addSorter('.js-sorter-asc', 'asc')
.addSorter('.js-sorter-desc', 'desc')
;
});
}(jQuery);
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Dynamitable</title>
<link href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css" rel="stylesheet">
<style>
<!--
.glyphicon {
cursor: pointer;
}
input, select{
width: 100%;
}
.second, .glyphicon-chevron-down, .glyphicon-chevron-up{
color: red;
}
-->
</style>
</head>
<body>
<div class="col-xs-12 col-sm-12 col-md-10 col-md-offset-1 col-lg-10 col-lg-offset-1">
<h1><span class="first">Dynami</span><span class="second">table</span></h1>
<div class="table-responsive">
<!-- Initialization
* js-dynamitable => dynamitable trigger (table)
-->
<table class="js-dynamitable table table-bordered">
<!-- table heading -->
<thead>
<!-- Sortering
* js-sorter-asc => ascending sorter trigger
* js-sorter-desc => desending sorter trigger
-->
<tr>
<th>Name
<span class="js-sorter-desc glyphicon glyphicon-chevron-down pull-right"></span>
<span class="js-sorter-asc glyphicon glyphicon-chevron-up pull-right"></span>
</th>
<th>Email
<span class="js-sorter-desc glyphicon glyphicon-chevron-down pull-right"></span>
<span class="js-sorter-asc glyphicon glyphicon-chevron-up pull-right"></span>
</th>
<th>Age
<span class="js-sorter-desc glyphicon glyphicon-chevron-down pull-right"></span>
<span class="js-sorter-asc glyphicon glyphicon-chevron-up pull-right"></span>
</th>
<th>Account
<span class="js-sorter-desc glyphicon glyphicon-chevron-down pull-right"></span>
<span class="js-sorter-asc glyphicon glyphicon-chevron-up pull-right"></span>
</th>
<th>Scoring
<span class="js-sorter-desc glyphicon glyphicon-chevron-down pull-right"></span>
<span class="js-sorter-asc glyphicon glyphicon-chevron-up pull-right"></span>
</th>
</tr>
<!-- Filtering
* js-filter => filter trigger (input, select)
-->
<tr>
<th>
<!-- input filter -->
<input class="js-filter form-control" type="text" value="">
</th>
<th>
<!-- select filter -->
<select class="js-filter form-control">
<option value=""></option>
<option value="@dynamitable.com">dynamitable.com</option>
<option value="@sample.com">Sample</option>
</select>
</th>
<th><input class="js-filter form-control" type="text" value=""></th>
<th><input class="js-filter form-control" type="text" value=""></th>
<th><input class="js-filter form-control" searchType="exact" type="text" value=""></th>
</tr>
</thead>
<!-- table body -->
<tbody>
<tr>
<td>Freddy Krueger</td>
<td>freddy.krueger@sample.com</td>
<td class="text-right">122</td>
<td class="text-right">2300$</td>
<td class="text-right">+15</td>
</tr>
<tr>
<td>Clint Eastwood</td>
<td>clint.eastwood@sample.com</td>
<td class="text-right">62</td>
<td class="text-right">48 500$</td>
<td class="text-right">+12</td>
</tr>
<tr>
<td>Peter Parker</td>
<td>peter.parker@dynamitable.com</td>
<td class="text-right">22</td>
<td class="text-right">210$</td>
<td class="text-right">-5</td>
</tr>
<tr>
<td>Bruce Wayne</td>
<td>bruce.wayne@dynamitable.com</td>
<td class="text-right">42</td>
<td class="text-right">-8500$</td>
<td class="text-right">+2</td>
</tr>
<tr>
<td>Jackie Chan</td>
<td>jackie.chan@sample.com</td>
<td class="text-right">32</td>
<td class="text-right">-250.55$</td>
<td class="text-right">0</td>
</tr>
<tr>
<td>Bruce Lee</td>
<td>bruce.lee@sample.com</td>
<td class="text-right">32</td>
<td class="text-right">510$</td>
<td class="text-right">-7</td>
</tr>
</tbody>
</table>
</div>
</div>
<!-- jquery -->
<script src="http://code.jquery.com/jquery-1.11.3.min.js"></script>
<!-- dynamitable -->
</body>
</html>
关于javascript - 与 Dynamitable 库精确匹配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54335783/
感觉我在这里遗漏了一些明显的东西,所以提前道歉。无论如何,这是我尝试转换的一些数据a: acct_num year_prem prem exc 001 20
我正在尝试将表中的模式与用户话语 匹配。 string userUtterance = "I want identification number for number of customers";
当尝试在 Precise 上链接 gccgo 时,出现此链接错误: matt@matt-1005P:~/src/gopath/src/meme$ gccgo cmd/meme/main.go -o m
假设我有以下数据和命令: clc;clear; t = [0:0.1:1]; t_new = [0:0.01:1]; y = [1,2,1,3,2,2,4,5,6,1,0]; p = interp1(
假设我有以下数据和命令: clc;clear; t = [0:0.1:1]; t_new = [0:0.01:1]; y = [1,2,1,3,2,2,4,5,6,1,0]; p = interp1(
我总是想给精确匹配比只匹配前缀的分数更高的分数(例如,“ball”在与“ball*”匹配时应该比“ballistic”得到更高的分数)。 我当前(详细)的方法是在创建 PrefixQuery 时始终执
有什么解决方法可以让我在 Android 中使用 long 或 double 来寻找音频文件中的位置吗?目前 seekTo 只接受 ints 参数。我想更精确(比如在十分之一秒内) int resID
我的 replacingOccurrences 函数有问题。我有一个这样的字符串: let x = "john, johnny, johnney" 我需要做的只是删除“john” 所以我有这段代码:
我正在使用 BeautifulSoup 进行网页抓取。我有这段代码来提取 a 标签的值,但它似乎不起作用。显示错误: AttributeError: 'int' object has no attri
我要在带有标记顶点和标记有向边的图上寻找一种不精确的图匹配算法。我的任务是检测两个图表的变化以将它们显示给开发人员(想想颠覆差异)。我已经实现了基于禁忌搜索 ( this ) 的优化算法,但我无法让该
我有两个网站: example.com 和 yyy.com 他们都有类似的网络应用程序,但在不同的服务器上。我想让 Apache 将所有路径请求重定向到 example.com 与 完全相同的方式yy
因此,我尝试合并两个公司信息数据库(从现在起表 A 和表 B),其中最常见(且可靠)的单一引用点是网站 URL。表 A 已更新,表 B 待更新。 我已经从表 A 中提取了 URL,并使用 PHP 清理
我正在 http://classicorthodoxbible.com/new.html 上制作效果主要描述中的 Angular 色,包裹在自己的跨度中,从他们通常的休息地点移动到随机位置,然后通过指
我目前正在使用我的 Raspberry Pi 及其内置 UART 输入编写 MIDI 合成器。 在某个时间点,为了启用 MIDI 输入的实时回放,我必须设置一种环形缓冲区以与 OpenAL 一起使用,
在 C 中,当设置了一个 float 时, int main(int argc, char *argv[]) { float temp = 98.6f; printf("%f\n",
实现 MP3 无间隙循环的最佳可能性是什么?目前我正在使用 AVAudioPlayer 并将 .numberOfLoops() 属性设置为 -1 但可以听到,轨道重新启动。情况并非如此,例如使用 Tr
我想创建不一定是“正确”矩阵的“类矩阵”对象。但是,确切地说,“类矩阵”是什么意思? 示例 1 > image(1:9) Error in image.default(1:9) : argument
给定一个像这样的 XML 文档: john &title; 我想解析上面的 XML 文档并生成其所有实体已解析的副本。因此,给定上述 XMl 文档,解析器应输出: john
需要说明的是,这种方法不是我要找的: 事实上,此方法会调整 ImageField 的大小。我想将 Image 对象的大小调整为特定且精确的无比例分辨率。有什么办法吗? --编辑-- 对我来说,Ima
我正在尝试使用 TF2.0 eager 模式执行精确的 GP 回归,基于来自 https://colab.research.google.com/github/tensorflow/probabili
我是一名优秀的程序员,十分优秀!