插件 jQuery.quicksearch 中文API文档

🌙
手机阅读
本文目录结构

插件 jQuery.quicksearch 中文API文档 https://github.com/DeuxHuitHuit/quicksearch

jQuery quicksearch plug-in

A jQuery based plug-in for filtering large data sets with user input

This is an improved fork of the original work of riklomas https://github.com/riklomas/quicksearch. This plugin is now maintained by @DeuxHuitHuit

Project pages

Examples

Usage

Note that the usage has changed in the latest version of quicksearch, the code is not backwards compatible, the form and input are not build by the script any more.

$(input_selector).quicksearch(elements_to_search, options);

Example on table rows

/* Example form */
<form>
	<input type="text" id="search">
</form>

/* Example table */
<table>
	<tbody>
		<tr>
			<td>Test cell</td>
			<td>Another test cell</td>
		</tr>
	</tbody>
</table>

<script src="jquery.js"></script>
<script src="jquery.quicksearch.js"></script>
<script>
	$('input#search').quicksearch('table tbody tr');
</script>

Example on the <th> elements on a table row

$('input#search').quicksearch('table tbody tr', {
	selector: 'th'
});

Example of how to use with JS

var qs = $('input#id_search_list').quicksearch('ul#list_example li');
$('ul#list_example').append('<li>Loaded with Ajax</li>');
qs.cache();

Example of how to use with Ajax

var qs = $('input#search').quicksearch('table tbody tr');
$.ajax({
	'type': 'GET',
	'url': 'index.html',
	'success': function (data) {
		$('table tbody tr').append(data);
		qs.cache();
	}
});

Options

  • delay Delay of trigger in milliseconds
  • selector A query selector on sibling elements to test
  • stripeRows An array of class names to go on each row
  • loader A query selector to find a loading element
  • caseSensitive Maintain original case of searchable content when comparing to query, instead of converting to lowercase. Defaults to false.
  • noResults A query selector to show if there’s no results for the search
  • bind Event that the trigger is tied to. Defaults to ‘keyup search’
  • resetBind Event that the reset event is tied to. Defaults to ‘reset’
  • removeDiacritics Remove diacritics from the search input. Defaults to false.
  • minValLength Establish a minimum length that the search value must have in order to perform the search. Defaults to 0.
  • onBefore Function to call before trigger is called
  • onAfter Function to call after trigger is called
  • onValTooSmall Function to call when the value does not exceeds the minValLength option.
  • onNoResultFound Function to call when no results are found. The normal behavior (show the no result panel) is canceled when you specify this parameter. You get the quicksearch instance in parameter so you can manually call the no result behavior.
  • show Function that will add styles to matched elements
  • hide Function that will add styles to unmatched elements
  • prepareQuery Function that transforms text from input_selector into query used by ’testQuery’ function
  • testQuery Function that tells if a given item should be hidden It takes 3 arguments:
    • query prepared by ‘prepareQuery’
    • stripped text from ‘selector’
    • element to be potentially hidden

Callbacks

Functions are always call’d or apply’d, so except this to be the plugin object.

For example:

$('input#search').quicksearch('table tbody tr', {
	'delay': 100,
	'selector': 'th',
	'stripeRows': ['odd', 'even'],
	'loader': 'span.loading',
	'noResults': 'tr#noresults',
	'bind': 'keyup keydown',
	'minValLength': 2,
	'removeDiacritics': true,
	'onBefore': function () {
		console.log('on before');
	},
	'onAfter': function () {
		console.log('on after');
	},
	'onValTooSmall': function (val) {
		console.log('value ' + val + ' is too small');
	},
	'show': function () {
		$(this).addClass('show');
	},
	'hide': function () {
		$(this).removeClass('show');
	}
	'prepareQuery': function (val) {
		return new RegExp(val, "i");
	},
	'testQuery': function (query, txt, _row) {
		return query.test(txt);
	}
});

Help make quicksearch better!

If you have a bug fix, the best way to help would be to:

  • Fork the project by clicking “Fork this project” at the top of this page
  • Clone your version of quicksearch from your Github account to your computer
  • Checkout the dev branch
  • Fix and commit the bugs, then push your version to your Github account
  • Click “pull request” at the top of my Github page
  • Please create the “Pull Request” to push in the branch

I can’t promise to answer every question about quicksearch, but please do report bugs here.

License

Now licensed under the MIT License: http://deuxhuithuit.mit-license.org

Credits

jQuery quicksearch was made by Rik Lomas at Lomalogue. It is now maintain by Deux Huit Huit

Thanks to Seth F. for fixes and Krzysiek Goj for the testQuery and prepareQuery option updates

AXIHE / 精选资源

浏览全部教程

面试题

学习网站

前端培训
自己甄别

前端书籍

关于朱安邦

我叫 朱安邦,阿西河的站长,在杭州。

以前是一名平面设计师,后来开始接接触前端开发,主要研究前端技术中的JS方向。

业余时间我喜欢分享和交流自己的技术,欢迎大家关注我的 Bilibili

关注我: Github / 知乎

于2021年离开前端领域,目前重心放在研究区块链上面了

我叫朱安邦,阿西河的站长

目前在杭州从事区块链周边的开发工作,机械专业,以前从事平面设计工作。

2014年底脱产在老家自学6个月的前端技术,自学期间几乎从未出过家门,最终找到了满意的前端工作。更多>

于2021年离开前端领域,目前从事区块链方面工作了