GithubHelp home page GithubHelp logo

riklomas / quicksearch Goto Github PK

View Code? Open in Web Editor NEW
681.0 29.0 264.0 238 KB

A jQuery plugin for searching through tables, lists, etc quickly

Home Page: http://www.lomalogue.com/jquery/quicksearch/

JavaScript 100.00%

quicksearch's Introduction

THIS PROJECT IS VERY MUCH DEAD AND NOT MAINTAINED. IT'S BEEN 6+ YEARS SINCE THE LAST UPDATES. DON'T EXPECT THIS TO WORK.

jQuery quicksearch plug-in

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

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 type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="jquery.quicksearch.js"></script>
<script type="text/javascript">
	$('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
  • noResults

    A query selector to show if there's no results for the search
  • bind

    Event that the trigger is tied to
  • onBefore

    Function to call before trigger is called
  • onAfter

    Function to call after trigger is called
  • 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

For example:

$('input#search').quicksearch('table tbody tr', {
	'delay': 100,
	'selector': 'th',
	'stripeRows': ['odd', 'even'],
	'loader': 'span.loading',
	'noResults': 'tr#noresults',
	'bind': 'keyup keydown',
	'onBefore': function () {
		console.log('on before');
	},
	'onAfter': function () {
		console.log('on after');
	},
	'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
  • Fix and commit the bugs, then push your version to your Github account
  • Click "pull request" at the top of my Github page

I can't promise to answer every question about quicksearch, but please do report bugs here or send me a message on Github.

You can watch quicksearch for updates or follow me on Github and on Twitter.

License

Under the same licenses as the jQuery library itself: http://docs.jquery.com/License

Credits

jQuery quicksearch is made by Rik Lomas at Lomalogue

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

quicksearch's People

Contributors

riklomas avatar tankchintan avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

quicksearch's Issues

Debug

How to debug jquery from my .net page

How to define a context to search?

Hey,

I'm having a problem defining a context for the plugin to search.

The thing is, i have multiple input-texts (the user can add more and more from a button) and i'm doing something like this:

$('.inp_txt').quicksearch('ul.myList li');

For each input-text, i have a list, like a selectbox, the displays the results while typing. The problem is, when the user starts typing on the first input, the plugin displays all of the .myList from all the other inputs. I need it to display only the list from the input-text where the user are.

I think i cannot use diferent classes for each list and call the plugin for each one specifically, because more inputs can be added via JS while navigating.

Is there anyway i can define the context, using $(this) or something else, so the plugin knows its to search only in that specific list?

Thanks!

filter all but header rows?

Loving your quicksearch... I'm using it to filter all sorts of tables.
But often, I create some kind of grouping, by having several rows underneath a header row. As in:

[table]
[tr]
[th colspan="2"]Section 1[/th]
[/tr]
[tr]
[td]actual row 1[/td][td]actual value 1[/td]
[/tr]
[tr]
[td]actual row 2[/td][td]actual value 2[/td]
[/tr]
[/table]

Now when I search, I want to search both the td's as the th's. That's working fine since my selector sais: "table#result tbody tr".

But if something is matched in a detailed row, the "header" row isn't matched thus hidden.

I'm looking for a way to always include the header part of a search result, because else it becomes hard to distinguish different results with the same name.

Something like that possible at all? I thought about using the Show option to include a selector for the header part, but then...then Hide option would remove it again?

Edit: by the way: if I use "table#result tbody tr:has(td)" as selector, it works as expected, except that now all headers are shown, instead of only the ones who have search results...

Runs slowly on IE

Dude ,this quick search plugin takes time to load n the IE browser...

Hide all rows when search input is empty

It would be nice to have a mode where all rows are hidden if the search input box is empty.

Forgive me if this is already possible. I'm still a bit of a n00b. I can't figure out how to do this with the current quicksearch.

Slows down the searching

Hey,I have made use of ur quickseacrh plugin..it searches properly..but the thing is,it slows down the mechanism as the number of items are being inserted..

Running query on page load

I cannot figure out how to run a quicksearch search on a form/table where the query string has been passed from another page. Is this even possible?

Action on multiple tables

Hi,

The previous version of Quicksearch was able to act on multiple tables on the same page as long as thses tables have the same ID.
Is that possible to be done in this new version?

Custom option to create cache value

Actually, cache of texts is created as
cache = t.map(function () {
return e.strip_html(this.innerHTML);
});

A want to created search based on metadata of elements, not thei innerHTML. My suggestion is something like:

cache = t.map(options.customCache || function () {
return e.strip_html(this.innerHTML);
});

Thanks,
Bruno Grossi

Reset Button

hi.. is there a way to add an reset button?

i use quicksearch with tablesorter and tried different things to reset the table.
i found your(?) old script modified @ http://michael.theirwinfamily.net/demo/jquery/modified-quicksearch/index.html
but it isnt compatible to the last one.

i tried some javscript/html code to reset (clear) the search input.
i was able to remove the word in the searchinput but the table doesnt get back to beginning.

hope you understand my problem. sorry for my bad english!

best regards

bernte

Solution for searching in multiple columns

The default testQuery checks each character of the query on a stripped string of a table row. This resulted in unwanted behavior in my table that shows ID's, full dates and other numbers. If you want to search on search chunks, use this function:

'testQuery': function(query, txt, _row){
    var arr = query.toString().split(" ");
    for (var i = 0; i < arr.length; i += 1) {
        if (txt.indexOf(arr[i]) === -1) {
            return false;
        }
    }
    return true;
}

Show results separately

It's a very good script, and I'm trying to implement this on my site for searching through a list of categories. Everything seems to be well and fine, but I still need one thing that should have been provided in the script itself (not aware if it's really in script).

I've been trying to include a separate span / div / ... for listing out the results, instead listing the result under the table or ul . For eg., listing out a ul result in a separate div id. Hope someone can guide me for this...

Search for special characters as normal characters

Hi,

Your plugin is really great, thanks for it I love it! :)

I just happen to have this case on one of my websites.

People can search a page where some names can contain charcaters like ä, Ä, Ò, in brief, characters with accents.
But people don't necessary write the accents and as a result some elements that should appear do not...

Would it be tricky to manage this case? like passing an array of special/normal characters as an argument?

Trouble with the selector option

Hello! Does the selector option support selectors that include classes? I have this:

$("input#txtSearch").quicksearch("table tr", {
"delay": "1000",
"selector": "td.address"
});

I only want to search in the td elements with class address. When I try this, however, the search doesn't appear to do anything.

Am I just wrong?

not working in IE

Hello,
i've implemented the search, all going good in firebox but is not working on internet explorer 7.0

How to call quickSerach on click of serach button

Problem::

Thanks for help in adv...

we have a table on which quicksearch is implemented , search function should be initialized when the user clicks on search link. is there any way to call quicksearch from javascript or on a onlick event ?

and also search should be implemented on multiple tables..is there any way to pass the table id's explicitly...

Code here::

function startSearch(){
alert("inside StartSearch method");
var phrase=document.getElementById('searchText').value;
alert("phrase"+phrase);

$('input#searchText').quicksearch('table#firsttable tbody tr');
alert("out of start search");

}


                                    <td width="43%" align="right" valign="middle">


                                    <h utputText value="&#160;" /> </td>

                                    <td width="9%" valign="middle">
                                    <tr:commandLink>
                                       <tr:image shortDesc="Refresh" source="/images/icon_refresh_24.gif" 
                                            inlineStyle="width:24px;height:24px;border:0px;" 
                                            onclick="window.location.reload(true)">
                                        </tr:image>
                                    </tr:commandLink>
                                    </td>
                                </tr>
                            </table>
                            <!-- End page title --> <!-- End r2 END PAGE TITLE and DESCRIPTION PANEL -->
                            </td>
                        </tr>

Document Details

Search

Script not loading on example page in IE9

This might affect other IE versions, as well. The error is "Script from was blocked due to mime type mismatch". This causes the example to fail. This is stock IE9 with no settings changed. To fix, just change the page to not load the script from github, which serves it as a plain text file.

using a list instead of table

Hi,

I really liked this script and its working like a charm. Super.. but I want to implement the same in a list box using select stms..Is this possible..Any help is great..thank you sooo much. thank you.

takes time to load the page

My page takes around 7 to 8 seconds to load with quicksearch present.
The table i am building has around 500 records only.
i am using a simple $('input#id_search').quicksearch('table#table_example tbody tr');
is there any way to speed it up or display few records first ?

Using quicksearch based on a dynamically rendered table

Hey Riklomas, your quicksearch has been extremely helpful in finding information quickly, but I am new to jquery and have implemented the search ability in a dynamically rendered table. The table does not use elements and I cannot define them without messing up the rendered table. Is there any other way to search on a single column besides using your selector: 'th'?

Multiple Tables

Is it possible to use quicksearch to search across multiple tables if they shared a class?

Feature Request: Make strip_html() user configurable

Users of the API can choose what text to search in a row. This allows removing some elements that contain text that you do not want to search, as well as using more aggressive regexp. For example, I want a regexp that strips more whitespace (to improve search speed) and does not concatenate words.

The method strip_html returns an object that is passed to testQuery. This is good because the returned object does not necessarily have to be a string.

A developer can implement strip_html/testQuery that performs all types of searches, not limited to string contains.

It's a very simple code change, basically move the method to options.

Quicksearch - not working in IE9

Hi, thanks a lot for a quick search!!

It works perfect, but unfortunately, I found, that it is not work for IE9... I tried to look your SuperTable - result the same.. not working :(

Selection based on query or different pages

Hello,
Your script is indeed very good..
Actually i wanted to know if it can search the table based on sql query directly if i want to display all records on pages consisting of page numbering where lies several records..

Can it be done??

Thx and regards

Use of .on() is Incompatible with jQuery < 1.7

First of all, great plugin! Thanks for publishing it...

The issue is on Line 172:

Because the behaviors are bound with .on() instead of .bind(), this plugin is incompatible with any jQuery versions earlier than 1.7. I know it's not ideal to be using an older version of jQuery, but I was just working on a site that is using 1.2.6, and a simple change back to .bind() solved this problem.

Thanks

Nbsp html tag

I have a table that have td and last td have html  

Finally, all rows are found with quicksearch when i provide to input "nbsp" !!

$(this).on is not a function

After the merge of Jan 18 I am getting a '$(this).on is not a function' error when running $('input#search').quicksearch('li')

Is it a bug or something I have to change on my side?

Can't access matchedResultsCount on onAfter() method

I can't access because matchedResultsCount is changed on this, and this on onAfter() is the option object.

2 solutions is:

  • options.matchedResultsCount = numMatchedRows;
    or
  • Use options.onAfter.call(this)

Bruno Grossi

Search input values also

If you have inputs in your table and you want to search by input value, you can do that by changing "strip_html" function.

replace function with this:

this.strip_html = function (input) {
var output = input.replace(new RegExp('<input.value="(.?)".*>', 'gi'), "$1").replace(new RegExp('<[^<]+>', 'g'), "");
output = $.trim(output.toLowerCase());
return output;
};

Added:

.replace(new RegExp('<input.value="(.?)".*>', 'gi'), "$1")

Browser back

Hi
My quicksearch input field is always emptied when returning to the quicksearch page using the back button.
Is there a way to make sure (or more probable) browsers will retain the input field contents on "back"?
Thanks!
Urs

clear search functionality

Hey,

there is no refresh option (out side of the search box ) to clear the searched item and display the original table again.

Could you provide a selector to do this refresh functionality

Quicksearch 'unhides' hidden table rows during initialization

During init the query string is "" so quicksearch sets the style.display to "" which unhides it.

You can fix this by adding a filter to the lines that build jq_results (line 106 or so) and t (line 112 or so).
jq_results = $(target).not(':hidden')

link with popup (rel="modal") don't work

Hi,

I have an issue with quicksearch.

I have ​​a table of data wich is generated from mysql.
At the end of each row is a link that opens in a popup(rel="modal" from another jQuery) where I can edit the data in that row.
When I use quicksearch it will not open the popup, after I delete the searched phrase the popup shows up.

Does anyone have an idea what is wrong and how can I fix this?

Group of suggestions

Dear Sirs
I would like to thank you first for your help on working with multiple tables as using a class instead of ID solved the issue.
May you please help me in the following points:
1- The filtering action runs on keypressed is there a way to make it run by a button. (i.e. the table is not filter unless a button is pressed). This will help in many ways especially on huge tables or when working on multiple tables.

2- There are 2 ways on filtering (all columns or using tag) what if we were able to filter according to the column name.

3- Each time entering a new word in the input box reset the table then apply the filtering on all records. What if there is a way to give the option of filtering all the records or just the result of previously filtered. I tried this by making the following changes in your example:

$('input#id_search').quicksearch('table#table.myQS tbody tr'); $('input#id_search2').quicksearch('table#table.myQS tbody tr', ...................... then entering a word in "id_search" then another word in "id_search2" which filtered the result of the first filtering action.

4- Is there a way to get the count of filtered records (rows) in the header or footer of each table???

5- How to make onafter run an external function (i.e. function found in .js file).

6- Where can i get a documentation for Quicksearch plugin ? as there are methods isn't mentioned in the example (i.e. using a class instead of ID).

I know that maybe some of my questions is stupied but i'm novice to javascript i'm used to pascal & VB.net.

Sorry for bieng long but i really apreciate your work it is really a magic.

Gabriel Mina

Support for multiple selectors?

Any chance of adding the ability to search for multiple selectors. I'm trying to make this into an exposed filter for the Drupal Views module, and adding a common class to each cell isn't the most elegant solution. Is it utterly out of scope to allow an array?

Anyhow, great great great plugin by the way! Thanks very much!

quicksearch stripe functionality breaks when incorporated with jquery.tablesorter

First and foremost, Great job and thank you for creating this plugin!

This is actually more of an FYI than an issue...

When creating reports that are shown through html tables, it is nice to incorporate a couple of plugins that would provide customers more options to see what they really need. However, every time we try to execute the integration of different features, it is very much likely that we encounter dependency/function conflict problems. This now boils down to the issue i encountered when i integrated tablesorter with quicksearch...

Problem:
Here is the process i executed that made me come across the problem.

  1. i utilized the tablesorter plugin and used the 'zebra' widget to manage the row striping. This works well, as expected.
  2. i applied the quicksearch plugin and used the stripeRows: ['oddRow', 'evenRow'] to manage the striping when search operation is being done. This works well when no sorting is implemented on any column of the table. However, when a sort is enforced on any column of the table, it messes up the striping.
    *** The cause of this problem is mainly because of the table caching wherein the old structure of the table is being used instead of the actual table view that is displayed in the page.

Solution:
After encountering the problem i looked into the quicksearch code to understand it's behavior and come up with a one-liner fix that is shown below.

    this.stripe = function () {
        if (typeof options.stripeRows === "object" && options.stripeRows !== null)
        {
            var joined = options.stripeRows.join(' ');
            var stripeRows_length = options.stripeRows.length;

            jq_results = $(target); // Add this line to update the table structure/chronological order of the sorted table.
            jq_results.not(':hidden').each(function (i) {
                $(this).removeClass(joined).addClass(options.stripeRows[i % stripeRows_length]);
            });
        }

        return this;
    };

I haven't looked into the downside of this change yet (overhead in performance, etc.), but i guess it is safe to say that the right behavior is achieved.

Best regards,

  • Jack

quicksearch overloads jQuery methods

Right now it is impossible to do this:

var search = $('form input.search').quicksearch();
search.val('').trigger('keyup');

and have the search form reset, showing all rows.

The problem lies in the way that quicksearch uses this, which in the context of a plugin, refers to the matched element, not the $.fn.quicksearch class. To correct this, either use $.fn.quicksearch.func instead of this.func or simply func and disallow outside access.

HTML5 Search

It would seem that when you have something like (I've only tested Chrome) and that input loses focus, it doesn't list all items in the table again (the place holder text now returns to this input, and I would guess that it has a value of ''). My guess would be to simply run the sort again when the search bar loses focus.

searching is not properly

when ever i am searching 'b' result is showing all values respective of there is no b..but when i am typing bbb. i am not getting any values.

Search: b

Delete Edit User Name First Name Last Name Email Password Country Registration Date Update Date
Delete Edit gg2 hfg hello [email protected] 12345 infd 5/12/2012 10:32:24 PM
Delete Edit ssd ssa aaa [email protected] 12345 India 5/12/2012 10:36:45 PM

Rebind quicksearch after an asynchronous postback

hi,

i am using quick search in a asp.net web application with a table and a textbox, like in your examples, which works like a charm after a pageLoad.
i have asynchrouns postbacks (using updatepanl). i am able to reload the text which was written in the textbox after the async. postback, but i can't force quicksearch to rebind the search after the postback.

my code looks like:
var foo = $i(tb).quicksearch('table#{0} tbody tr' , tablename);

which run without problems in the first load / page load. I tried too something like:
foo("info1").keyup();

but did not work. What can i do ?

ps: i run my script after the postback with: Sys.WebForms.PageRequestManager.getInstance().add_endRequest(Methodename);

Thanks in advance

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.