Skip to content
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

Multiple placeholder columns causes error. Single placeholder column works. #89

Open
LegendaryFire opened this issue Jun 24, 2022 · 9 comments
Labels
bug Something isn't working

Comments

@LegendaryFire
Copy link

LegendaryFire commented Jun 24, 2022

For some reason, when using placeholder columns, only one can be used. However, when two or more placeholder columns are required the following error is thrown.

Exception: Column 1 ("custom_column_2") is not orderable.

Here is some sample code.

    column_defs = [
        {
            'name': 'custom_column_1',
            'title': 'Custom 1',
            'placeholder': True,
            'orderable': False,
            'searchable': False,
            'visible': True,
        }, {
            'name': 'custom_column_2',
            'title': 'Custom 2',
            'placeholder': True,
            'orderable': False,
            'searchable': False,
            'visible': True,
        }, {
            'name': 'first_name',
            'searchable': True,
            'visible': False,
        }, {
            'name': 'last_name',
            'searchable': True,
            'visible': False,
        }, {
            'name': 'birth_month',
            'searchable': True,
            'visible': False,
        }, {
            'name': 'birth_day',
            'searchable': True,
            'visible': False,
        },

    ]
    def customize_row(self, row, obj):
        if obj.first_name and obj.last_name:
            row['custom_column_1'] = f'{obj.first_name} {obj.last_name}'
        else:
            row['custom_column_1'] = 'Unknown'

        if obj.birth_month and obj.birth_day:
            row['custom_column_2'] = f'{obj.birth_month}, {obj.birth_day}'
        else:
            row['custom_column_2'] = 'Unknown'

        return

Then, if I try setting custom_column_1 and custom_column_2 to be orderable, the following error occurs.

File "C:\Users\User1\PycharmProjects\djangoProject1\venv\lib\site-packages\django\db\models\sql\query.py", line 1677, in names_to_path raise FieldError( django.core.exceptions.FieldError: Cannot resolve keyword 'custom_column_2' into field. Choices are: first_name, last_name, birth_month, birth_day

@morlandi morlandi added the bug Something isn't working label Jun 24, 2022
@morlandi
Copy link
Owner

Thank you @LegendaryFire , I'll flag this as a bug to be investigated, but since I work on this project occasionally I can't guarantee any time schedule

@LegendaryFire
Copy link
Author

LegendaryFire commented Jun 24, 2022

Thanks for the prompt response @klavman. For any others who may experience the same issue, a temporary workaround would be to use a column which can be mapped to a field in the model instead of adding an additional placeholder column. See the example below.

    column_defs = [
        {
            'name': 'first_name',
            'title': 'Full Name',
            'searchable': True,
            'visible': True,
        }, {
            'name': 'last_name',
            'searchable': True,
            'visible': False,
        }, {
            'name': 'birth_month',
            'title': 'Birth Month & Day',
            'searchable': True,
            'visible': True,
        }, {
            'name': 'birth_day',
            'searchable': True,
            'visible': False,
        },

    ]

    def customize_row(self, row, obj):
        if obj.first_name and obj.last_name:
            row['first_name'] = f'{obj.first_name} {obj.last_name}'
        else:
            row['first_name'] = 'Unknown'

        if obj.birth_month and obj.birth_day:
            row['birth_month'] = f'{obj.birth_month}, {obj.birth_day}'
        else:
            row['birth_month'] = 'Unknown'

        return

Simply set the first_name and birth_month column to visible, and then override the values which are rendered to those cells. Of course, with the code in my first post, leave the last_name and birth_day columns as not visible so we can still use the values of them to search.

@LegendaryFire
Copy link
Author

LegendaryFire commented Jun 28, 2022

Update: Even with one placeholder, the problem still persists unfortunately.

@morlandi
Copy link
Owner

@LegendaryFire hopefully I'll be able to check this during the next weekend.
The concept of "placeholder" comes from the original project I started with and to be honest I had rare occasions to use it

@LegendaryFire
Copy link
Author

@morlandi No problem. I'll take a good look and see if perhaps I can come up with a solution as well. Thank you for your hard work, this really is the way to go when working with tables in Django

@tboulogne
Copy link
Contributor

@morlandi hello hope you're well :-). Did you work on this placeholder bug ? I expérience the same problem for now.
Thanks for all.

@morlandi
Copy link
Owner

Hello @tboulogne, nice to hear of you.

I haven't been actively involved in the project for some time because I'm busy with other activities.
However, I keep an eye on the issues because sooner or later I hope to find the time to fix them, at least the most significant ones

I take this opportunity to wish you a happy new year ;)

Mario

@tboulogne
Copy link
Contributor

Hello Mario,

I wish you a pleasant year too :-) ! Hope your best wishes comes to reality.

I hope to find some time to look into this too :-). Keep in touch.

Thierry

@tboulogne
Copy link
Contributor

tboulogne commented Jan 1, 2023

@morlandi No problem. I'll take a good look and see if perhaps I can come up with a solution as well. Thank you for your hard work, this really is the way to go when working with tables in Django

I think it's quite normal. We are on server-aide mode. Queryset did not know about placeholder field... as datatables knows... So placeholder should not be orderable or filterable...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants