indianghost / livesearch Goto Github PK
View Code? Open in Web Editor NEWLive Search Plugin is an amazing jQuery plugin developed by Achraf BELLAALI allows you to search in any table HTML at the real time
License: MIT License
Live Search Plugin is an amazing jQuery plugin developed by Achraf BELLAALI allows you to search in any table HTML at the real time
License: MIT License
Hi @IndianGhost,
Good work so far on this plugin. It seems like a good start for a good one in the future.
Although this was declared as a jQuery plugin, it still lacks the definition of one. A jQuery plugin should give a user a way for initializing it when they want and/or a way for destroying (detach it from the table) it when they feel the need for it.
By initializing above, I meant it should give a user, like me, a way to attach it to whatever table I want and use whatever filter input (search box as you describe it). It should never restrect me from using my own Ids or names.
In order to reach this, you will need to provide a way for passing some settings/options to the plugin. Below is a possible definition for this plugin:
(function($) {
var defaultOptions = {
// By default, this plugin will look for table with the Id "live-search-table"
table: "#live-search-table"
};
function LiveSearch(options, searchInput) {
this.options = $.extend({}, defaultOptions, options);
this.searchInput = searchInput;
// Init the plugin
this.init();
}
$.extend(LiveSearch.prototype, {
init: function() {
// TODO: Attach events to the search input
},
destroy: function() {
// TODO:
// Unbind the events and remove the plugin instance
// from the input
}
});
$.fn.liveSearch = function(options) {
// If nothing is selected, exit.
if (!this.length) {
console.warn( "Nothing selected, can't validate, returning nothing." );
return;
}
// Get the search input element
var searchInput = this[0];
// Check if a liveSearch instance for this input was already created
var pluginInstance = $.data(searchInput, "live_search" );
if (pluginInstance) {
return pluginInstance;
}
// Create a new instance of the plugin
pluginInstance = new LiveSearch(options, searchInput);
// Assign it to the search input for subsequent usage
$.data(searchInput, "live_search", pluginInstance);
// Finally, return the create instance
return pluginInstance;
};
})(jQuery);
Usage:
$("#live-search-input").liveSearch({ table: "#my-table" });
For a starter project on how to create a jQuery plugin, see: https://github.com/jquery-boilerplate/jquery-boilerplate
In case you want to have a much broader knowledge on the most used jQuery patterns in JS world, you can check this repository: https://github.com/jquery-boilerplate/jquery-patterns
You can also read this book by Addy Osmani (free to read online): https://addyosmani.com/resources/essentialjsdesignpatterns/book/
Feel free to ping me whenever you need some help.
Hope this helps and good luck with your project.
in js/search.js
you may avoid making the "_this" variable; a global variable.
so what I can advise you is:
var _this = this;
Can you please add usage steps.
how to access the Live-Demo from the GitHub repo.
you may add an URL to your repo ๐
https://www.jqueryscript.net/demo/Table-Live-Search-Plugin-jQuery/
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.