-
Notifications
You must be signed in to change notification settings - Fork 35
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Searchable collumns #8
Comments
I will need some more details to implement the test case and the fix. How to you declare both the client-side (javascript initialization) and server-side ( |
I use Django 1.5. $('#browser-table').dataTable({
"bPaginate": true,
"sPaginationType": "bootstrap",
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": "{% url "contacts:data_table" %}",
"aoColumnDefs": [ {
"sClass": "nowrap",
"bSearchable": false,
"bSortable": false,
"aTargets": [ -1 ]
}]
}); On the server side I don’t do anything special: class ContactsTableView(DatatablesView):
model = Person
fields = (
'first_name',
'last_name',
'email',
'pk',
) The problem is having the primary key in the column. I need it to generate the buttons links on the client side.
You should find a way to use a different operator than icontains on primary keys. |
Maybe as an example you can have a look at the php code here: http://datatables.net/development/server-side/php_mysql They search only on the columns that are searchable. |
The issue seems legitimate and is reproducible on Django 1.6, but not in a way that original poster supposed. Take a look at this model: class FirstModel(models.Model):
related_item = models.ForeignKey(SecondModel) Let's say we've got two tables, both have class BrokenFirstModelTableView(DatatablesView):
"""
self.global_search(qs) will fail with
TypeError: Related Field got invalid lookup: icontains
"""
model = FirstModel
fields = {
'related_item': 'related_item',
}
class WorkingFirstModelTableView(DatatablesView):
"""
And this table will do just fine.
"""
model = FirstModel
fields = {
'related_item': 'related_item__pk',
} It looks like Whether this behavior is to be considered a documentation issue or a genuine bug, is a good question. As about OP, my wild guess is that he's got a foreign key field somewhere in his |
I'm sorry, I didn't had time to look into it. I will fix this issue this week-end. |
Never mind, this issue doesn't heavily affect me since there is an easy workaround. Thanks for your awesome projects! I use With best wishes and admiration, |
You're very welcome !!! |
Hi,
I'm pretty new to django so hopefully everything I say will be correct.
If I add the primary key has a column text search will crash the app because pk__icontains is not a legal operation.
The simplest way I found to get around the problem is making the column not searchable. But this feature doesn't seem to be supported in eztables.
I've modified the global_search method the following way:
Or is there another way of stoping the app from crashing with having the primary key (pk column) in the data?
Thank you
The text was updated successfully, but these errors were encountered: