filter table search
JavaScript
new Vue({
el: '#demo',
data: {
sortKey: 'name',
reverse: false,
searchName: '',
searchOperator: '',
searchAge: '',
columns: ['name', 'age'],
newUser: {},
search: "",
name: "",
age: "",
users: [
{ name: 'John', age: 50 },
{ name: 'Jane', age: 22 },
{ name: 'Paul', age: 34 },
{ name: 'Kate', age: 15 },
{ name: 'Amanda', age: 65 },
{ name: 'Steve', age: 38 },
{ name: 'Keith', age: 21 },
{ name: 'Don', age: 50 },
{ name: 'Susan', age: 21 }
]
},
methods: {
sortBy: function (sortKey) {
this.reverse = (this.sortKey == sortKey) ? !this.reverse : false;
this.sortKey = sortKey;
},
filterByName : function(user) {
// no search, don't filter :
if (this.searchName.length === 0) {
return true;
}
return (user.name.toLowerCase().indexOf(this.searchName.toLowerCase()) > -1);
},
filterByAge : function (user) {
// no operator selected or no age typed, don't filter :
if (this.searchOperator.length === 0 || this.age.length === 0) {
return true;
}
if (this.searchOperator === '>') {
return (user.age > this.age);
} else if (this.searchOperator === '<') {
return (user.age < this.age);
}
},
orderBy : function (userA, userB) {
let condition = (userA[this.sortKey] > userB[this.sortKey]);
if (this.reverse) {
return !condition;
} else {
return condition;
}
}
},
computed: {
filteredPersons: function () {
return this.users
.filter(this.filterByName)
.filter(this.filterByAge)
.sort(this.orderBy);
}
},
});
Also in JavaScript:
- Title
- angular index of array
- Category
- JavaScript
- Title
- import dropdown react
- Category
- JavaScript
- Title
- how to do bubble sort in javascript
- Category
- JavaScript
- Title
- how to add row in angular dynamically
- Category
- JavaScript
- Title
- get date one week from now javascript
- Category
- JavaScript
- Title
- faunadb ref
- Category
- JavaScript
- Title
- expresiones ternarias javascript
- Category
- JavaScript
- Title
- how to format unix timestamp javascript
- Category
- JavaScript
- Title
- get variable from other javascript file
- Category
- JavaScript
- Title
- .push js
- Category
- JavaScript
- Title
- handling event in jsx
- Category
- JavaScript
- Title
- how to iterate through an object in javascript
- Category
- JavaScript
- Title
- how to add elements in javascript html
- Category
- JavaScript
- Title
- how to auto refresh page in javascript
- Category
- JavaScript
- Title
- how to add role in discord.js v12
- Category
- JavaScript
- Title
- Add disclaimer for best browser experience in angular
- Category
- JavaScript
- Title
- assign values to a table from javascript in VF page
- Category
- JavaScript
- Title
- how to loop object javascript
- Category
- JavaScript
- Title
- find highest number in array javascript
- Category
- JavaScript
- Title
- angular bootstrap not working
- Category
- JavaScript
- Title
- Alternating Sums
- Category
- JavaScript
- Title
- how to update jquery datatable row cell value
- Category
- JavaScript
- Title
- 404 json laravel
- Category
- JavaScript
- Title
- bubble sort javascript
- Category
- JavaScript
- Title
- how to debug javascript
- Category
- JavaScript
- Title
- https package node post request
- Category
- JavaScript
- Title
- filter array objects javascript
- Category
- JavaScript
- Title
- array.filter in js
- Category
- JavaScript
- Title
- array index javascript show only first 2 elements
- Category
- JavaScript
- Title
- close bootstrap modal with javascript
- Category
- JavaScript
- Title
- how to square a value in javascript
- Category
- JavaScript
- Title
- document ready
- Category
- JavaScript
- Title
- filter advantages in js
- Category
- JavaScript
- Title
- how to return the max and min of an array in javascript
- Category
- JavaScript
- Title
- add select option jquery
- Category
- JavaScript
- Title
- how to send an alert in javascript
- Category
- JavaScript
- Title
- Javascript compare two dates
- Category
- JavaScript
- Title
- how to print array backwards
- Category
- JavaScript
- Title
- get width of a dom element js
- Category
- JavaScript
- Title
- const{}=
- Category
- JavaScript
- Title
- brute force search javascript
- Category
- JavaScript
- Title
- Javascript compare two objects
- Category
- JavaScript
- Title
- append before jquery
- Category
- JavaScript
- Title
- how to get value in array object value using for loop in javascript
- Category
- JavaScript
- Title
- ExoPlayer with auto linking react native
- Category
- JavaScript
- Title
- "npm supertest
- Category
- JavaScript
- Title
- javascript ascending and descending
- Category
- JavaScript
- Title
- clearinterval javascript
- Category
- JavaScript
- Title
- convert jquery to string
- Category
- JavaScript
- Title
- add discord.js library
- Category
- JavaScript
- Title
- command to create custom pipe in angular 6
- Category
- JavaScript
- Title
- convert string to char array javascript
- Category
- JavaScript
- Title
- ascii to char in javascript
- Category
- JavaScript
- Title
- check if object has method javascript
- Category
- JavaScript
- Title
- how to find unique elements in array in javascript
- Category
- JavaScript
- Title
- how to pass a value to a react funtion without immediately firing it
- Category
- JavaScript
- Title
- express get query params from url
- Category
- JavaScript
- Title
- ajax with django
- Category
- JavaScript
- Title
- javascript clear all intervals
- Category
- JavaScript
- Title
- javascrip reverse text
- Category
- JavaScript
- Title
- fullcalendar react add event duration
- Category
- JavaScript
- Title
- elseif javascript
- Category
- JavaScript
- Title
- Cannot find module '.json'
- Category
- JavaScript
- Title
- angular material input
- Category
- JavaScript
- Title
- ajax .put
- Category
- JavaScript
- Title
- block comment js
- Category
- JavaScript
- Title
- add bootstrap to gatsby
- Category
- JavaScript
- Title
- How can I refresh a page with jQuery
- Category
- JavaScript
- Title
- how to get tomorrow date in javascript
- Category
- JavaScript
- Title
- banking program deposit and withdrawal using ajax call
- Category
- JavaScript
- Title
- bootstrap datepicker js cdn
- Category
- JavaScript
- Title
- how to enable click copy function using js
- Category
- JavaScript
- Title
- express middleware pass parameter
- Category
- JavaScript
- Title
- download image in nodejs
- Category
- JavaScript
- Title
- get the size of the browser jquery
- Category
- JavaScript
- Title
- csv export in react
- Category
- JavaScript
- Title
- buble sort in js
- Category
- JavaScript
- Title
- conditional jsx property
- Category
- JavaScript
- Title
- appendchild javascript
- Category
- JavaScript
- Title
- encode url javascript
- Category
- JavaScript
- Title
- how to change a string to number in javascript
- Category
- JavaScript
- Title
- integers to space separated string in javascript
- Category
- JavaScript
- Title
- default pool size in sequelize
- Category
- JavaScript
- Title
- check a checkbox jquery
- Category
- JavaScript
- Title
- find last element with class jquery
- Category
- JavaScript
- Title
- axios post data vue js
- Category
- JavaScript
- Title
- input output ionic
- Category
- JavaScript
- Title
- discord.js command prompt notification
- Category
- JavaScript
- Title
- for(let [key,val] in obj){ messageBody = messageBody.replace("{"+ key + "}",val) }
- Category
- JavaScript
- Title
- apache log format json
- Category
- JavaScript
- Title
- How to write on a web page javascript
- Category
- JavaScript
- Title
- get all entries in object as array hjs
- Category
- JavaScript
- Title
- difference between foreach and map in js
- Category
- JavaScript
- Title
- copy text on button click in jquery
- Category
- JavaScript
- Title
- increase-memory-limit not working node
- Category
- JavaScript
- Title
- how to instialise var in js
- Category
- JavaScript
- Title
- array to comma separated list js
- Category
- JavaScript
- Title
- check multiple ifield if it's blank in jquery
- Category
- JavaScript
- Title
- how to concatenate strings javascript
- Category
- JavaScript
- Title
- (function (g, d, a) {})(window, document, jQuery);
- Category
- JavaScript