Comments (1)
well, i just had to smoke this issue a bit to get the solution...
1st) add new prototype:
EditableGrid.prototype.filter1 = function(filterString, cols)
{
with (this) {
if (typeof filterString != 'undefined') {
this.currentFilter = filterString;
this.localset('filter', filterString);
}
// if filtering is done on server-side, we are done here
if (serverSide) return setPageIndex(0);
// un-filter if no or empty filter set
if (currentFilter == null || currentFilter == "") {
if (dataUnfiltered != null) {
data = dataUnfiltered;
dataUnfiltered = null;
for (var r = 0; r < getRowCount(); r++) data[r].visible = true;
setPageIndex(0);
tableFiltered();
}
return;
}
var words = currentFilter.toLowerCase().split(" ");
// work on unfiltered data
if (dataUnfiltered != null) data = dataUnfiltered;
var rowCount = getRowCount();
var columnCount = typeof cols != 'undefined' ? cols.length : getColumnCount();
for (var r = 0; r < rowCount; r++) {
var row = data[r];
row.visible = true;
var rowContent = "";
// add column values
for (var c = 0; c < columnCount; c++) {
if (getColumnType(c) == 'boolean') continue;
var displayValue = getDisplayValueAt(r, typeof cols != 'undefined' ? cols[c] : c);
var value = getValueAt(r, typeof cols != 'undefined' ? cols[c] : c);
rowContent += displayValue + " " + (displayValue == value ? "" : value + " ");
}
// add attribute values
for (var attributeName in row) {
if (attributeName != "visible" && attributeName != "originalIndex" && attributeName != "columns") rowContent += row[attributeName];
}
// if row contents do not match one word in the filter, hide the row
for (var i = 0; i < words.length; i++) {
var word = words[i];
var match = false;
// a word starting with "!" means that we want a NON match
var invertMatch = word.startsWith("!");
if (invertMatch) word = word.substr(1);
// if word is of the form "colname/attributename=value" or "colname/attributename!=value", only this column/attribute is used
var colindex = -1;
var attributeName = null;
if (word.contains("!=")) {
var parts = word.split("!=");
colindex = getColumnIndex(parts[0]);
if (colindex >= 0) {
word = parts[1];
invertMatch = !invertMatch;
}
else if (typeof row[parts[0]] != 'undefined') {
attributeName = parts[0];
word = parts[1];
invertMatch = !invertMatch;
}
}
else if (word.contains("=")) {
var parts = word.split("=");
colindex = getColumnIndex(parts[0]);
if (colindex >= 0) word = parts[1];
else if (typeof row[parts[0]] != 'undefined') {
attributeName = parts[0];
word = parts[1];
}
}
// a word ending with "!" means that a column must match this word exactly
if (!word.endsWith("!")) {
if (colindex >= 0) match = (getValueAt(r, colindex) + ' ' + getDisplayValueAt(r, colindex)).trim().toLowerCase().indexOf(word) >= 0;
else if (attributeName !== null) match = (''+getRowAttribute(r, attributeName)).trim().toLowerCase().indexOf(word) >= 0;
else match = rowContent.toLowerCase().indexOf(word) >= 0;
}
else {
word = word.substr(0, word.length - 1);
if (colindex >= 0) match = (''+getDisplayValueAt(r, colindex)).trim().toLowerCase() == word || (''+getValueAt(r, colindex)).trim().toLowerCase() == word;
else if (attributeName !== null) match = (''+getRowAttribute(r, attributeName)).trim().toLowerCase() == word;
else for (var c = 0; c < columnCount; c++) {
if (getColumnType(typeof cols != 'undefined' ? cols[c] : c) == 'boolean') continue;
if ((''+getDisplayValueAt(r, typeof cols != 'undefined' ? cols[c] : c)).trim().toLowerCase() == word || (''+getValueAt(r, typeof cols != 'undefined' ? cols[c] : c)).trim().toLowerCase() == word) match = true;
}
}
if (invertMatch ? match : !match) {
data[r].visible = false;
break;
}
}
}
// keep only visible rows in data
dataUnfiltered = data;
data = [];
for (var r = 0; r < rowCount; r++) if (dataUnfiltered[r].visible) data.push(dataUnfiltered[r]);
// refresh grid (back on first page) and callback
setPageIndex(0);
tableFiltered();
}
};
then declare array with ID's of cols to use and filter with .filter1:
var cols1 = [0, 1];
currentFilter = _$('filter').value;
editableGrid.filter1(currentFilter, cols1);
and onkeyup the same:
$('filter').onkeyup = function() {
var cols = [0, 1];
editableGrid.filter1($('filter').value+"", cols);
};
Hope some one would need that...
from editablegrid.
Related Issues (20)
- version 2.0 documentation
- Nested Json
- How to combined into existing data table.
- editablegrid.js at line 556
- 'tablecontent' update javascript capture event
- How to manually refresh grid
- Source data not updated when change data, click remove or duplicate button HOT 4
- Multiple search
- Tab navigation Issue HOT 1
- Jquery autocomplete inputs - combo Box
- How to send my own product id for update records HOT 10
- Different select options for each row? HOT 2
- Append returns "html" column to default HOT 5
- Cyrillic characters
- getRow passes invalid selector to JQuery
- cancleEditing and applyEditing missing this.
- Enter hh:mm:ss HOT 1
- Insert an image according to the field value
- dynamically update metadata
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from editablegrid.