Recent searches
No recent searches
Filter My activities section
Posted Dec 16, 2021
Hello,
I'm having an issue where I can't seem to find an answer to, but I can't imagine it's not possible.
In "My activities" section, the "requests_page" more specifically, I added a column where a date is specified (the last column "created" on the picture).
I put a condition where only certain values will show in the "created" column. The code was working well at this point.
However, the value of the last column can be empty. Other values in other columns are present.
What I want is to hide the entire row if the value of the last column is empty. (I used the ajax part in the code to show the last column with the values I want).
$('#hidetablerows > tbody > tr').has('td:empty').hide() : doesn't seem to work in this case but $("#hidetablerows").find("tr:gt(7)").remove(); shows the first 7 rows...
(hidetablerows is the ID of my table)
3
5 comments
Christopher Kennedy
I may need to see the entire table in the template for context on what is happening with your hide attempts. But before diving into that I want to float an alternative approach.
In your AJAX request success callback, it looks like you're checking to see if the value should be added to the table or left blank. If that's true, you can add an "empty" class to the cell for cases where no value should be present. Then you can use jQuery to hide the closest
<tr>
parent of elements with the empty class. For example:Let me know if you're still running into issues.
Best,
1
Ahlam Kern
Hi Christopher,
Thank you for your answer, it actually worked and that was exactly what I was looking for. Besides, there's this condition I want to put in the exact same code, I will explain below :
As you can see, in this code I put the condition : If the variable "value" is ">=" to the constant "date0".
However I actually want the "date0" to be a dynamic value and so, to put a condition where only values >= 6 months of creation (based on the last "Created at" column) to show on the list.
I put here the whole code :
<div class="my-activities-nav">
<div class="container">
<nav class="collapsible-nav">
<button type="button" class="collapsible-nav-toggle" aria-label="{{t 'toggle_navigation'}}" aria-expanded="false"></button>
<ul class="collapsible-nav-list">
<li aria-selected=true>{{t 'requests'}}</li>
<li>{{link 'contributions'}}</li>
<li>{{link 'subscriptions'}}</li>
</ul>
</nav>
</div>
</div>
<div class="container">
<header class="my-activities-header">
<h1>{{t 'my_requests'}}</h1>
<div class="my-activities-sub-nav">
<nav class="collapsible-nav collapsible-nav-border">
<button type="button" class="collapsible-nav-toggle" aria-label="{{t 'toggle_navigation'}}" aria-expanded="false"></button>
<ul class="collapsible-nav-list">
{{#each filters}}
{{#if selected}}
<li aria-selected=true>{{name}}</li>
{{else}}
<li><a href="{{url}}">{{name}}</a></li>
{{/if}}
{{/each}}
</ul>
</nav>
</div>
</header>
{{#form 'requests_filter' class='requests-table-toolbar'}}
<div class="search">
{{input 'query' id='quick-search' type='search' class='requests-search'}}
</div>
{{#if help_center.multiple_organizations_enabled}}
<div class="request-table-filter">
{{label 'organization' for='request-organization-select' class='request-filter request-filter-label'}}
{{select 'organization' id='request-organization-select' class='request-filter'}}
</div>
{{/if}}
<div class="request-table-filter">
{{subscribe}}
</div>
<div class="request-table-filter">
{{label 'status' for='request-status-select' class='request-filter request-filter-label'}}
{{select 'status' id='request-status-select' class='request-filter'}}
</div>
{{/form}}
{{#if query}}
<div class="requests-search-info meta-data">
{{t 'requests_search_results_info' count=requests.length query=query}}
</div>
{{else}}
{{#unless requests}}
<p class="no-activities">{{t 'no_requests'}}</p>
{{/unless}}
{{/if}}
<div class="requests">
{{#if requests}}
<table id="hidetablerows" class="table my-activities-table requests-table {{current_filter.identifier}}-requests">
<thead>
<tr>
<th>{{t 'subject'}}</th>
<th>{{t 'id'}}</th>
<th>{{#link 'requests' sort_by='updated_at'}}{{t 'last_activity'}}{{/link}}</th>
<th>
{{t 'status'}}
</th>
<th>{{#link 'requests' sort_by='Created_at'}}{{t 'created_at'}}Created at{{/link}}</th>
</tr>
</thead>
<tbody>
{{#each requests}}
<tr {{#is status 'closed'}} class="request-closed" {{/is}}>
<td class="request-info requests-table-info">
<a href="{{url}}" class="striped-list-title" title="{{subject}}">
{{#if subject}}
{{subject}}
{{else}}
{{excerpt description characters=50}}
{{/if}}
</a>
<!-- Visible on mobile -->
<div class="requests-table-meta meta-group">
<span class="meta-data">#{{id}}</span>
<span class="meta-data">{{date created_at timeago=true}}</span>
<span class="status-label status-label-{{status}}" title="{{status_description}}">
{{status_name}}
</span>
</div>
</td>
<td>#{{id}}</td>
<td>{{date updated_at timeago=true}}</td>
<td class="requests-table-status">
<span class="status-label status-label-{{status}}" title="{{status_description}}">
{{status_name}}
</span>
</td>
<td class="requests-table-created">
<div id="{{id}}"></div>
<script>
$.ajax({
url: 'https://myopla1571820429.zendesk.com/api/v2/requests/{{id}}.json',
dataType: 'json',
type: 'GET',
crossDomain: true,
contentType: 'application/json',
data: '',
processData: false,
success: function (data)
{
const date0 = Date.parse('2021-10-20T15:14:16Z');
var value = Date.parse(data.request.created_at);
var count = Object.keys(data.request.created_at).length;
var elm = document.getElementById("{{id}}");
if (value >= date0) {
elm.innerHTML = value;
} else {
elm.classList.add("empty");
}
$(".empty").closest("tr").hide();
},
Error: function (result) {
}
})
</script>
</td>
</tr>
{{/each}}
</tbody>
</table>
{{/if}}
</div>
{{pagination}}
</div>
0
Gorka Cardona-Lauridsen
Hi Ahlam Kern
Thank you for the feedback!
It may interest you to know that we are working on a way to allow configuration of which columns end users can see, sort and filter on without having to code it your self.
You can see a bit more details in the oficial comment on this post and follow it to keep up.
0
Gorka Cardona-Lauridsen
We are very happy to let you know that we have now added the ability to see custom fields to the new request list open beta and we will continue to add more features.
You can read more in this announcement.
While this does not (yet) solve the issue in this post, I thought you would find it relevant since we as part of the work on the new request list we are intending to add better filtering capabilities.
What may also interest you is that we have made the Request REST API allowed for end users, so you can now also build your own request list experience using the API.
1
Gorka Cardona-Lauridsen
Hi all
We are very excited to announce that users can now (pending rollout) filter their requests based on custom field values in the new request list experience. See the announcement here for all the details.
0