Skip to content

Commit

Permalink
This commit solved issue ubccr#222 and gets the filtered data on the …
Browse files Browse the repository at this point in the history
…webpage
  • Loading branch information
bhatiadheeraj committed Nov 5, 2020
1 parent 91ae1d9 commit 5552b17
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 2 deletions.
42 changes: 40 additions & 2 deletions coldfront/core/grant/templates/grant/grant_report_list.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<div class="card">
<div class="card-header">
<h4 class="d-inline"><i class="fas fa-trophy" aria-hidden="true"></i> Grants</h4>
<a class="btn btn-success float-right" href="{% url 'grant-download' %}" role="button"><i class="fas fa-download" aria-hidden="true"></i> Export to CSV</a>
<a class="btn btn-success float-right" id='Export_BTN' href="{% url 'grant-download'%}" role="button"><i class="fas fa-download" aria-hidden="true"></i> Export to CSV</a>
</div>
<div class="card-body">
{% if grant_list %}
Expand All @@ -38,7 +38,7 @@ <h4 class="d-inline"><i class="fas fa-trophy" aria-hidden="true"></i> Grants</h4
<tbody>
{% for grant in grant_list %}
<tr>
<td style="min-width: 400px">{{ grant.title }}</td>
<td style="min-width: 400px" id='grant_id'>{{ grant.title }}</td>
<td class="text-nowrap"><a href="{% url 'project-detail' grant.project.pk %}">{{ grant.project.pi.first_name }} {{ grant.project.pi.last_name }}</a></td>
<td class="text-nowrap">{{ grant.role }}</td>
<td class="text-nowrap">{{ grant.grant_pi }}</td>
Expand Down Expand Up @@ -72,6 +72,44 @@ <h4 class="d-inline"><i class="fas fa-trophy" aria-hidden="true"></i> Grants</h4
"bSortClasses": false,
"order": [[ 4, "desc" ]]
});
$('#grants-table').on('search.dt', function() {
var value = $('.dataTables_filter input').val();
console.log(value); // <-- the value
var table=document.getElementsByTagName('table');
var oTable = document.getElementById('grants-table');

//gets rows of table
var rowLength = oTable.rows.length;
var grant_title = [];
//loops through rows
for (i = 1; i < rowLength; i++){

//gets cells of current row
var oCells = oTable.rows.item(i).cells;

//gets amount of cells of current row
var cellLength = oCells.length;

//loops through each cell in current row
for(var j = 0; j < cellLength; j++){
/* get your cell info here */
var cellVal = oCells.item(0).innerHTML;
console.log(cellVal);
grant_title.push(cellVal);
}
}

var Export_BTN= document.getElementById('Export_BTN');
});
});

function setCook(name, value) {
var cookie = [
name,
'=',
JSON.stringify(value)
].join('');
document.cookie = cookie;
}
</script>
{% endblock %}
3 changes: 3 additions & 0 deletions coldfront/core/grant/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,9 @@ def get(self, request):

rows = []
grants = Grant.objects.prefetch_related('project', 'project__pi').all().order_by('-total_amount_awarded')
print(Grant.objects.prefetch_related('project', 'project__pi').filter())


for grant in grants:
row = [
grant.title,
Expand Down

1 comment on commit 5552b17

@bhatiadheeraj
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am sorry I mistakenly wrote solved instead of solves

Please sign in to comment.