Closed ChloeQuignot closed 8 months ago
Hi. I will look on you issue in next week. Sorry for delay, however I have a lot of work.
Hi. Today, I started looking on your issue. Unfortunately, I meet some troubles.
As I understand, you expect that after column manipulation (hide or show) URL in browser window will change. I don't think manipulating the URL in the browser is a good idea. Nevertheless, I understand your need and suggest using a slightly different approach.
I suggest next steps:
Please see on below example:
<!-- download button -->
<div id="button" class="btn" data-link="{% export_url 'csv' %}">Download table</a>
<script type="text/javascript"
src="{% static "django_tables2_column_shifter/js/django_tables2_column_shifter.min.js" %}">
</script>
<script type="text/javascript">
$(document).ready(function(){
$.django_tables2_column_shifter_init()
var button = $("#button");
button.click(function(){
// 1. get hidden columns
var hidden_columns = $.django_tables2_column_shifter_hidden();
console.log(hidden_columns);
// 2. add hidden columns to url
var url = button.data("link") + "?hidden_columns=" + hidden_columns;
console.log(url);
// 3. Open url in current window
window.location.replace(url);
});
});
</script>
Hi! Thank you so much for your time and sorry for my late reply, September was a bit of a rush...
I followed your suggestion and it seems to be working. I'm not very familiar with javascript so your code snippet was really useful to me. I have the impression though that adding it to the html somehow interferes with the column selection. What I observe is that the dropdown menu opens up but the column boxes in the menu aren't clickable. I'm not sure what could be causing this, do you have some ideas that come to mind?
I played around a bit and found that opening the new link in a new tab makes it (sort of) work (clickable columns in the menu + hidden columns taken into account at download) although the "frozen column" syndrome still appears just after the download. But refreshing the page makes it work again so I think I can live with it like that.
<a href="#" onclick="create_link('csv');return false;"><img src="{% static 'static/img/download_icon.png' %}" alt="logo_download" style="width:50px"/></a>
<script type="text/javascript"
src="{% static "django_tables2_column_shifter/js/django_tables2_column_shifter.min.js" %}">
</script>
<script type="text/javascript">
function create_link(format) {
var url = window.location.origin+window.location.pathname;
var params = window.location.search;
$.django_tables2_column_shifter_init()
// 1. get hidden columns
var hidden_columns = $.django_tables2_column_shifter_hidden();
console.log(hidden_columns);
// 2. add hidden columns to url
var newurl = url + "?" + params + "&exclude_columns=" + hidden_columns + "&_export=" + format;
console.log(newurl);
// 3. Open url in new tab
window.open(newurl,"_blank");
}
</script>
Which columns are not clickable ?
Are you able prepare some short video presenting this issue?
You can also send me a zip
archive with your code, and then I will look into.
Hello,
Thank you for this great package, it's just what I was looking for and it was quite simple to set up thanks to your detailed
README
! I am now able to show/hide columns dynamically while exploring the table and I am able to select the columns that I want to show by default.I was just wandering if there's also a way to save the table with just the columns that are showing in the web page (according to what columns were selected/deselected by the user). I've implemented the hack that was described in the
README
in which you add theexclude_columns=request.GET.get('exclude_columns').split(",")
parameter toTableExport
in the view function and it seems to work if I manually add&exclude_columns=species
to the download url (this excludes thespecies
column in the download) but I have trouble making it work without my intervention. I noticed, when I play around with showing/hiding columns in the web page, that it doesn't actually change the url (it doesn't add the exclude_columns parameter to the url with the columns that aren't showing) so I guess it's normal thatrequest.GET.get('exclude_columns').split(",")
isn't able to pick up the excluded columns since they don't appear in the url? Is this expected? Is there something that I forgot to add to make it work?Thank you in advance for your help and advice, Chloe
PS: below, a simplified version of the model, table, filter, view and template that I used.
app/models.py
app/tables.py
app/filters.py
app/views.py
app/urls.py
app/templates/app/db_explore.html