morlandi / django-ajax-datatable

A Django app which provides the integration of a Django project with the jQuery Javascript library DataTables.net
MIT License
204 stars 64 forks source link

date_input_to_isoformat #97

Open cnagytcorp opened 1 year ago

cnagytcorp commented 1 year ago

I can't get your example working, this function is part of what ? date_input_to_isoformat "Query.Deferred exception: date_input_to_isoformat is not defined ReferenceError: date_input_to_isoformat is not defined" Removing it than the table works but obviously no longer able to filter by date_range. Also how to make user__first_name and userlast_name in to 1 column ? If I just use user than cannot search user column "got error" Had to split it to make it work. `{'name': 'First name', 'foreign_field': 'userfirst_name', 'visible': True}, {'name': 'Last name', 'foreign_field': 'user__last_name', 'visible': True},` Documentation is extensive and looks great on first sight but for a beginner is difficult to understand what does what especially when english not the native language. Sorry for commenting here as issue but havent found a forum where django-ajax-datatable being discussed in dept. I'm greatly appreciate the work you put in to this, would like to learn more and make it usable in my project.

cnagytcorp commented 1 year ago

In time I have figured out that I need to add show_date_filter = True latest_by = 'created_at' to the main Class than I can use date range, also I have added date_input_to_isoformat to the extra data instead of extra_options. Still cant figure out how to use user as a column and be searchable. Any taught on that ? Tried to add list as a value for foreign_field {'name': 'employee', 'foreign_field': ('user__first_name', 'user__last_name'), 'visible': True}, that just brake the whole thing and no longer works at all.

morlandi commented 1 year ago

Hello @cnagytcorp, thank you for your interest in the project

To efficiently apply sorting and searching, i.e. delegating them to the database, each column of the javascript datatable must be associated with a specific column of the table in the database.

The criteria for formulating the search on the ORM side are automatically deduced from the context, while you would like to do a search on multiple columns.

I understand the need, and it seems interesting to me, but unfortunately it is not currently supported; it would be necessary to provide some mechanism for optionally replacing the criterion of the search on the column with an arbitrary expression.

Unfortunately I can't predict a short intervention in this sense, because I deal more with backend than with frontend, and for me this is a secondary project to which I can devote little time.

But I will keep the Issue open as a reminder, just in case.

cnagytcorp commented 1 year ago

Thanks for the explanation, it's becoming my new favorite table rendering tool, realy like the compact layout and the customizability. Unfortunately being a novice in Python-Django it's a frustrating (sometimes fun) learning curve for me. I do understand now why is this way, I don't think this is a bug, simply misunderstand it. I do have a question though ( I know this isn't a support forum), how would I get another models related field in to the table..

from user model

user_first_name, user_last_name,

from schedule model where user is foreign_key to user_id

user_schedule