Pegase745 / sqlalchemy-datatables

SQLAlchemy integration of jQuery DataTables >= 1.10.x (Pyramid and Flask examples)
MIT License
159 stars 67 forks source link

Fix #131: A mapper function to map the frontend columns data with backend. A new yadcf_data params. Some small improvements. #132

Open kartikeyas00 opened 3 years ago

kartikeyas00 commented 3 years ago

Regarding this issue, I have come up with a _map_columns_with_params private method in DataTables class in datatables.py module. This method compares columns data with the parameters data and map the correct column number to the columns data. As a lot of times in frontend columns are not in the correct order as they are in the backend. Also there are cases when extra dummy columns are added in the frontend and they disturb the sequencing, thus the results coming from the backend.

I am also proposing a new ColumnDT params which is yadcf_data

Why?

When the search method is set as yadcf_select, yadcf_multiselect and yadcf_autocomplete then always yadcf data object is being returned from the backend even when someone doesn't want it as in some cases the data can be defined in the frontend and no data is required from the backend.

For example: If a column contains only yearly data, then one can easily define the options in the frontend for yadcf and backend doesn't have to look at all the records in that column and retrieve the unique records as the option. It can also save server processing.

This PR provides the yadcf_data params for ColumnDT class which can be set to False when we don't want the yadcf_data. It would be default to True

Other improvements proposed

  1. yadcf_multi_select method in search_methods.py module have been improved to handle null from the JavaScript.

  2. In DataTables class add_columns method have been replaced with with_entities method in the query object as add_columns method was adding a column or columns on the top of the list of columns who already exists in the table or query butwith_entities replaces the select list with the current entities which means it would only have the columns selected with the with_entities clause.

Pegase745 commented 3 years ago

Thanks for this, will take a look. Could you possibly revert all the linting diffs to make it easier to read please? Single quotes + 4 spaces indentation are the first differences I see

tdamsma commented 3 years ago

@Pegase745, I propose to run black formatter first (see #133), then rebase this PR on to get a proper diff.

@kartikeyas00 I don't fully understand what usecase this is solving. But then I haven't looked at this codebase in a while. If I recall correctly you can either use yadcf (or one of the other options) to

kartikeyas00 commented 3 years ago

I can possibly come up with an example in the next couple of days. But yadcf_data parameter will basically tell the server to either send or not send the options data from the server to client, in case when the client doesn't want it. Also it happens in the case of these three search options yadcf_select, yadcf_multiselect and yadcf_autocomplete. I would suggest you to look at _set_yadcf_data method in datatables.py module.

kartikeyas00 commented 3 years ago

@tdamsma @Pegase745 Any update on this?

tdamsma commented 3 years ago

@tdamsma @Pegase745 Any update on this?

There are still a bunch of merge conflicts, making it really hard to see what the scope of the changes is. Can you resolve them and run black on your code to minimize the diff?