Kreyu / data-table-bundle

Streamlines creation process of the data tables in Symfony applications. NOT PRODUCTION READY.
https://data-table-bundle.swroblewski.pl
MIT License
75 stars 14 forks source link

[Persistance] Filters still won't restore in URL on initial request #119

Closed CMH-Benny closed 3 months ago

CMH-Benny commented 3 months ago

I updated to latest version in order to test the restoring of filters. Filter Buttons work now as expected perfectly fine! Thank you for fixing this. I would have answered in the other issue, but it was closed and I guess this is the best way to cantact you?

I updated to the latest version and after some adjustments it seems to work fine in my project.

So I added the following to my controllers.json:

            "state": {
                "enabled": true,
                "fetch": "eager"
            }

I do see the controller to be executed:

kreyu--data-table-bundle--state #initialize
kreyu--data-table-bundle--state #connect

However URL remains without params when I come back to the datatable page, so persitence is read successfully all filters are there and work, but the URL is not overwritten, anything I can do to help to understand the issue?

Steps to reproduce (on my end)

Kreyu commented 3 months ago

Hey!

I would have answered in the https://github.com/Kreyu/data-table-bundle/issues/107, but it was closed and I guess this is the best way to cantact you?

I'm getting notifications even on closed issues, so you can comment on those as well (if related, of course), and I can reopen them if necessary πŸ˜„

However URL remains without params when I come back to the datatable page, so persitence is read successfully all filters are there and work, but the URL is not overwritten, anything I can do to help to understand the issue?

Are you using a custom theme that modifies the base kreyu_data_table block? The turbo-frame should contain a data-kreyu--data-table-bundle--state-url-parameters-value param with JSON-encoded URL parameters. Or maybe those are empty in your case?

https://github.com/Kreyu/data-table-bundle/blob/7cadde7b0d4a6206aff89733cc90a3d4e24a2ee5/src/Resources/views/themes/base.html.twig#L12-L16

The url_query_parameters variable should be accessible inside the view of your data table - you can check it by dumping the data_table.vars.url_query_parameters (assuming DataTableView you are passing to the view is named data_table). Its contents are generated in the base DataTableType:

https://github.com/Kreyu/data-table-bundle/blob/7cadde7b0d4a6206aff89733cc90a3d4e24a2ee5/src/Type/DataTableType.php#L396-L429

CMH-Benny commented 3 months ago

Thanks for the fast reply! <3

I'm getting notifications even on closed issues, so you can comment on those as well (if related, of course), and I can reopen them if necessary πŸ˜„

Sadly no, the comment button was disabled, so i couldn't put the reply there, else that would have been my choice, maybe it is some kind of setting to allow that specifically?

Are you using a custom theme

Yes I do, but I don't override those blocks and I checked my HTML and all necessary attributes are there. I debugged into the JS code and it seems that for some reason it can't read the this.urlQueryParametersValue however, the attribute itself has a string with the filters:

<turbo-frame id="kreyu_data_table_my_table" 
                       target="_top" 
                       data-controller="kreyu--data-table-bundle--state" 
                       data-kreyu--data-table-bundle--state-url-parameters-value="{&quot;filter_my_table&quot;:{&quot;search&quot;:{&quot;value&quot;:&quot;Test&quot;}},&quot;page_my_table&quot;:1,&quot;limit_my_table&quot;:25}"
                       >

So for some reason the conversion to an object seems not to work on my side, it's an empty object even tho there is a proper data attribute available, maybe it somehow can't parse the string and thus returns empty object?

Kreyu commented 3 months ago

Dammit, the HTML attribute is named ...url-parameters... instead of ...url-query-parameters..., I swear it somehow worked before I published a release (or I forgot to rebuild assets after changing the naming) πŸ˜… Should be fixed in 0.21.1, thanks for reporting the issue!

Sadly no, the comment button was disabled, so i couldn't put the reply there, else that would have been my choice, maybe it is some kind of setting to allow that specifically?

Hmm, I've had multiple issues in this repo with people commenting on already closed issues, so I'm not sure. Although, thanks for the info

CMH-Benny commented 3 months ago

Dammit, the HTML attribute is named ...url-parameters... instead of ...url-query-parameters...

Oh, wow even I didn't see it, I debugged into it, I tried to adjust the json_encoded string to see if something changes, and I also checked that attribute, but because it's so long I also didn't realize there is a -query- missing in between - Good catch!

thanks for reporting the issue!

Thank you for taking a look and fixing it so fast, I updated it and now it works perfectly fine, for filters, pages and sorting, thank you so much <3

Hmm, I've had multiple issues in this repo with people commenting on already closed issues, so I'm not sure. Although, thanks for the info

Actually you are right, I am just plain dumb, the button was disabled, but it was because I didn't put any text into the box πŸ€¦β€β™‚οΈ I can't really tell why I didn't even realize there is the comment box, it was like it doesn't exist in that moment, kinda worrying. So sorry that I created the new issue here for no reason in the end, next time I will stick to the existing issue πŸ€žπŸ˜„

I will hit close and comment now, all looking good πŸ‘Thanks again!