Closed FigaCZ closed 1 month ago
I'm also experiencing this problem and as mentioned above there is no documentation about how to implement this properly.
Can anyone explain how this should be implemented - is there additional javascript required to get it working?
Thanks!
Same here.
+1
+1
Same here...
It could be nice to have documentation for this...
Hi everybody! Did anyone come up with something with that filter? The author ignores our questions and no documentation. @MadCat34 @kapcus @Gerben321 @FigaCZ @mash-potato47
nope, filter option doesn't work
Stale issue message
nah, not stale, just ignored :+)
I neither wrote nor use nor reviewed this feature: https://github.com/omines/datatables-bundle/pull/120
Not much I can do to help with an issue I don't really fully understand myself. I'm keeping it open so other people can help each other, that's how open source works.
There, now it has a label showing I also have no clue about how to solve this issue.
I neither wrote nor use nor reviewed this feature: #120
Not much I can do to help with an issue I don't really fully understand myself. I'm keeping it open so other people can help each other, that's how open source works.
I didn't mean it personal :) Just read it and it sounds a bit harsh, didn't mean it like that ;)
I have no clue on how to fix it either, otherwise I would have opened a PR :+)
Stale issue message
+1
+1
Hi all! I'm migrating from SG Datatable to Omines Datatable as the previously mentioned is no longer maintained. I can't figure out how to configure column filters. I'm experiencing the same problem reported by other user in this issue. The issue is in closed status because no one can find a solution? Any info / help will be appreciated.
Given all the comments above I'd recommend considering this specific feature 'broken'.
We use the library a lot at our company, so we do the maintenance, but only on core features that we developed ourselves and use. It would appear this contributed feature wasn't implemented well unfortunately, nor documented, so we'll likely remove it during an upcoming maintenance round.
I managed to have column filtering on a project of mine, for now it's still early (like 30sec ago) later, most likely next week, I'll create a minimal reproduction repo and link it here, no idea if it's the bundle's intend way but if it works it works.
To sum it up for people who want to try I added this to the initComplete config inside my twig template
initComplete: function () {
let api = this.api();
api.columns().every(function () {
let column = this;
let title = column.header().textContent;
let th = column.header();
// Create input element
let input = document.createElement('input');
input.classList.add('form-control');
input.addEventListener("click", function(e) {
e.stopPropagation();
});
input.placeholder = title;
th.replaceChildren(input);
// Event listener for user input
let debouncedFunction = debounce(() => {
if (column.search() !== this.value) {
let idx = [...th.parentNode.children].indexOf(th);
let val = input.value;
if(val.length < 3) return;
api.column(idx + ':visible')
.search(val ? '%'+val+'%' : '')
.draw();
}
},500)
input.addEventListener('keyup', debouncedFunction);
});
}
and to my column I added those options :
["searchable" => true, "filter" => $nameFilter, "operator" => "LIKE"]
and $nameFilter is just a TextFilter on wich I called to set method and put "operator" => "LIKE" as well
And this adds a text input to each column that perfoms a like operation in the backend
@Shotman I assume your solution search for the actual displayed entries (pageLength). Not in the database. Is that correct? This will be suiteable for small datasets and if all entries are displayed at once.
Works on the database, but after some time using that it's not perfect, saving to query parameters doesn't work, url encoding fails because of the added % etc it's a bandaid to have something that kinda works but isn't a real solution but it could be a stepping stone for something solid and stable
Thanks for the fast response. I will wait for the reproducer repo. It that is still the next step.
Here is the repo, https://github.com/Shotman/datatable-repo, not the pretiest readme or anything but does the job to recreate what I did on my personal project
EDIT : and from what I've seen like just now, it's likely to be vulnerable to SQL injections with a good enough crafted filter so yeah do not use in production ^^'
Stale issue message
So I've dug into the code here - this is not a small fix as it's been broken for a LONG time and never been forward ported In between the breakage there are PHP 8.x fixes that have to happen, symfony fixes that have to happen, twig fixes that have to happen...
But I need it for work so - meh
apparently there was an issue with the twig templates from quite a long time ago when settings/options for the base datatables class were refactored. As a "fix" the part that generated the input/js for doing the searching was just .. commented out I updated the twig templates, uncommented the lines, fixed some calls, added a constructor to the filter abstract class (seriously ick I shouldn't have to call set to use a filter without a PHP error.... ) but I'm still banging up against the JS side
I'm working on a fix (and warning I'm on Symfony 7 at this point) on a fork at this point
I have it about 90% working
https://github.com/burroaktoolinc/datatables-bundle/tree/feature_column_searching
That branch has the php/twig side working
Issue is I have to have this in the initComplete in the datatables declaration to get the JS side of the inputs hooked up - might be a better way? Also this has no debounce which probably should be added. Any JS gurus have ideas?
initComplete: function () {
let api = this.api();
api.columns().every(function () {
const that = this
// Attach to input fields
$('input', this.footer()).on('keyup change clear', function () {
if (that.search() !== this.value) {
that.search(this.value).draw()
}
})
$('select', this.footer()).on('change', function () {
that.search(this.value).draw()
})
})
}
I have it working now, but it required quite a bit of rework with some features/options copied over from the global search changes made - and it doesn't support multiple filters on a single column (yet)
And the js initComplete is still the way to "hook up" the inputs/selects which is not fabulous
I have it working now, but it required quite a bit of rework with some features/options copied over from the global search changes made - and it doesn't support multiple filters on a single column (yet)
And the js initComplete is still the way to "hook up" the inputs/selects which is not fabulous
Need any help on this? I'd like to see this merged so we can use it haha
@Wuffz
At this point I don't have a lot of impetus to contribute the fix back here - branch is freely available in my fork if you want to try to get it "right" enough to get merged here - https://github.com/burroaktoolinc/datatables-bundle/tree/feature_column_searching
It's working for us off our fork with the caveat of no multiple filters (cause we don't need it)
Stale issue message
Hello, maybe I didn't search docs deeply, but I am not able to get column filter displayed. I have this setup.
Controller:
datatables.yaml
I am not able to see column filter. What is wrong? Setup or datatable template. Thanks for reply.