Filtering single column
Hello,
Will it be possible to filter single columns, like in the jQuery plugin?
https://datatables.net/examples/api/multi_filter.html
Thank you.
It's possible. Using the event event:dataTableLoaded, you can fetch the ID of the table. So with this, you can add the code to add the single column filtering.
See Plnkr for example.
It works. Thank you very much.
Hi Louis,
I was just trying to reuse the code sample for adding filtering input boxes per column, however I get the following error: TypeError: Cannot read property 'columns' of undefined, triggered at this point.
var table = loadedDT.DataTable;
// Apply the search
table.columns().eq(0).each(function(colIdx) {
When I console.log the contents of loadedDT, that's all I get:
loadedDT: Object {id: "tags"}
so it seems that id is the only property.
I am using the following version:
* angular-datatables - v0.2.0
* https://github.com/l-lin/angular-datatables
Any clue for what is going wrong in my case?
The plnkr in my previous comment is using the dev version of angular-datatables that includes the feature that emit the DataTables and dataTable object along with the ID of the DataTable. That's why it's undefined with the version you are using.
Do I understand correctly, that I need to replace
<script src="../bower_components/angular-datatables/dist/angular-datatables.js"></script>
with
<script src="../bower_components/angular-datatables/dist/angular-datatables.renderer.js"></script>
?
I did so, however the issue persists:
loadedDT Object {id: "tags"} tags.js:50
TypeError: Cannot read property 'columns' of undefined
No, you will need the dev version.
Looks like you are using bower, then in your bower.json:
{
....
"dependencies": {
...
"angular-datatables": "dev",
....
}
}
If you want to have a dependency to a stable version, for your information, I will release the v0.2.1 this sunday (if everything goes right).
Fingers crossed for the new release. I will get back to filters and report once I ask another question now :)
I issued:
$ bower install --save
bower not-cached git://github.com/l-lin/angular-datatables.git#dev
bower resolve git://github.com/l-lin/angular-datatables.git#dev
bower checkout angular-datatables#dev
bower resolved git://github.com/l-lin/angular-datatables.git#3c05e6a2f9
bower install angular-datatables#3c05e6a2f9
angular-datatables#3c05e6a2f9 bower_components/angular-datatables
├── angular#1.2.26
├── datatables#1.10.2
└── jquery#2.1.1
And the contents of bower_components/angular-datatables are.
The index.html file sources the following:
<script src="bower_components/angular-datatables/dist/angular-datatables.js"></script>
Overall: the loadedDT.DataTable still contains a single property - id.
Have you tried clearing your browser cache?
Works fine for me:

Just tried - issue persists.
I am not sure that the console log tells me that bower actually installed the dev version. I still see v0.2.0 referenced in my index.html.
That's something on your side :sweat_smile:
Good, I will try to get it fixed today and report.
Hi,
so, I have the following in my bower.json dependencies:
"angular-datatables": "dev",
and the $ bower info angular-datatables tells me that the following versions are available:
bower angular-datatables#* cached git://github.com/l-lin/angular-datatables.git#0.2.0
bower angular-datatables#* validate 0.2.0 against git://github.com/l-lin/angular-datatables.git#*
{
name: 'angular-datatables',
version: '0.2.0',
author: 'l-lin',
main: 'dist/angular-datatables.js',
ignore: [
'.bowerrc',
'.editorconfig',
'.git*',
'.jshintrc',
'Gruntfile.js',
'test',
'node_modules',
'src',
'.travis.yml',
'vendor',
'data.json',
'data1.json',
'demo',
'favicon.png',
'index.html',
'README.md',
'server',
'styles',
'_config.yml',
'grunt',
'images',
'package.json'
],
dependencies: {
angular: '>=1.2.6',
jquery: '>=1.11.0',
datatables: '>=1.9.4'
},
devDependencies: {
'angular-mocks': '1.2.6',
bootstrap: '3.0.1',
'angular-bootstrap': '0.10.0'
},
homepage: 'https://github.com/l-lin/angular-datatables'
}
Available versions:
- 0.2.0
- 0.1.1
- 0.1.0
- 0.0.3
- 0.0.2
- 0.0.1
Now, I first reverted back to v0.2.0, and then used the install command with a #dev suffix.
$ bower install angular-datatables#dev --save
bower angular-datatables#dev not-cached git://github.com/l-lin/angular-datatables.git#dev
bower angular-datatables#dev resolve git://github.com/l-lin/angular-datatables.git#dev
bower angular-datatables#0.2.0 cached git://github.com/l-lin/angular-datatables.git#0.2.0
bower angular-datatables#0.2.0 validate 0.2.0 against git://github.com/l-lin/angular-datatables.git#0.2.0
bower angular-datatables#dev checkout dev
bower angular-datatables#dev resolved git://github.com/l-lin/angular-datatables.git#83ce3847da
Unable to find a suitable version for angular-datatables, please choose one:
1) angular-datatables#dev which resolved to 83ce3847da
2) angular-datatables#0.2.0 which resolved to 0.2.0 and is required by zap-adm-angPrefix the choice with ! to persist it to bower.json
? Answer:: 1
This updated my bower.json file, to "angular-datatables": "dev",, however when I open the angular-datatables.js file in the bower_components/angular-datatables/dist/ directory, the version still remains 0.2.0.
Dang it... :)
Try to clear your bower cache with the command bower cache clean.
Done that before.
Looks like you have to download it manually :sweat_smile:
Great, thank you.
loadedDT now looks like yours.
By the way, is there a way to make search-in-column work with the following option?
.withOption('serverSide', true)
Right now, the input into search fields is being ignored as I type, and unless I comment out the option above.
And another thing: for every key press in a filter input at a certain column the colIdx is being triggered twice, for instance in this part:
table.columns().eq(0).each(function(colIdx) {
$('input', table.column(colIdx).footer()).on('keyup change', function() {
console.log("colIdx", colIdx);
table
.column(colIdx)
.search(this.value)
.draw();
});
});
Console returns this upon a press on a single key in colIdx=2
colIdx 2 tags.js:89
colIdx 4 tags.js:89
The same thing happens for all other colIdxs. colIdx===4 is being printed every time. There are 4 columns in total.
I assume, as a result - the search does not produce expected results.
For your first question, I think you will need to add the columnFilter plugin. Given your example, it only triggers once.