bogdan / datagrid

Gem to create tables grids with sortable columns and filters
MIT License
1.02k stars 116 forks source link

URLs with Anchors and Search reset button #252

Closed fabriciofreitag closed 5 years ago

fabriciofreitag commented 5 years ago

If an URL with an anchor (i.e: "/books/1#readers") is passed to datagrid_form_for

The ancor is disregarded by the reset button: <a class="datagrid-reset button" href='/books/1'>Reset</a>

Expected: <a class="datagrid-reset button" href='/books/1#readers'>Reset</a>

bogdan commented 5 years ago

anchor is not passed to backend by the HTTP standard. So the link that retain anchor can not be generated because backend doesn't know about it. You can simulate the behavior only using JavaScript. Try something like this:

jQuery(function() {
  jQuery('.datagrid-reset').each(function(i, element) {
    jQuery(element).attr('href', jQuery(element).attr('href') + window.location.hash);
  });
});
fabriciofreitag commented 5 years ago

@bogdan thanks for the quick reply. but then why the filtering (search button) works as expected when there's an anchor(keeping the selected tab) while reset sends me to the previous page?

bogdan commented 5 years ago

I can not confirm that. On my end, anchor vanishes for both Reset and Search buttons.