Skip to content

Commit

Permalink
Feat: add dropdown menu and adjust column width (#25) (#26)
Browse files Browse the repository at this point in the history
Feat: add dropdown menu and adjust column width
  • Loading branch information
gurdeep330 authored Mar 26, 2024
1 parent ed371aa commit c3d92b3
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 92 deletions.
4 changes: 2 additions & 2 deletions docs/custom.css
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ table{
}

/* change the with of first column */
/* thead tr th:first-child,
thead tr th:first-child,
tbody tr td:first-child {
width: 400px;
min-width: 300px;
max-width: 400px;
word-break: break-all;
} */
}
74 changes: 4 additions & 70 deletions overrides/main.html
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@
new DataTable('#table1', {
order: [[5, 'desc']],
"columnDefs": [
{"className": "dt-center", "targets": "_all"},
{ width: '30%', targets: 0 }
{"className": "dt-center", "targets": "_all"}
],
pageLength: 5,
layout: {
Expand All @@ -52,8 +51,7 @@
new DataTable('#table2', {
order: [[3, 'desc']],
"columnDefs": [
{"className": "dt-center", "targets": "_all"},
{ width: '30%', targets: 0 }
{"className": "dt-center", "targets": "_all"}
],
pageLength: 5,
layout: {
Expand All @@ -63,41 +61,9 @@
}
});
new DataTable('#table3', {
initComplete: function () {
this.api()
.columns()
.every(function () {
let column = this;

// Create select element
let select = document.createElement('select');
select.add(new Option(''));
column.footer().replaceChildren(select);

// Apply listener for user change in value
select.addEventListener('change', function () {
column
.search(select.value, {exact: true})
.draw();
});

// keep the width of the select element same as the column
select.style.width = '100%';

// Add list of options
column
.data()
.unique()
.sort()
.each(function (d, j) {
select.add(new Option(d));
});
});
},
// order: [[3, 'desc']],
"columnDefs": [
{"className": "dt-center", "targets": "_all"},
{ width: '25%', targets: 1 }
{"className": "dt-center", "targets": "_all"}
],
pageLength: 5,
layout: {
Expand All @@ -107,41 +73,9 @@
}
});
new DataTable('#table4', {
initComplete: function () {
this.api()
.columns()
.every(function () {
let column = this;

// Create select element
let select = document.createElement('select');
select.add(new Option(''));
column.footer().replaceChildren(select);

// Apply listener for user change in value
select.addEventListener('change', function () {
column
.search(select.value, {exact: true})
.draw();
});

// keep the width of the select element same as the column
select.style.width = '100%';

// Add list of options
column
.data()
.unique()
.sort()
.each(function (d, j) {
select.add(new Option(d));
});
});
},
// order: [[3, 'desc']],
"columnDefs": [
{"className": "dt-center", "targets": "_all"},
{ width: '30%', targets: 0 }
{"className": "dt-center", "targets": "_all"}
],
pageLength: 5,
layout: {
Expand Down
24 changes: 4 additions & 20 deletions templates/overview.txt
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
<tbody>
{% for article in most_cited_articles %}
<tr>
<td><a href="{{article.url}}">{{article.title}}</a></td>
<td><a href="{{article.url}}">{{article.title}}</a><br></td>
<td>{{ article.authors}}</td>
<td>{{ article.publicationDate}}</td>
<td>{{ article.journal}}</td>
Expand All @@ -97,7 +97,7 @@
<tbody>
{% for article in most_recent_articles %}
<tr>
<td><a href="{{article.url}}">{{article.title}}</a></td>
<td><a href="{{article.url}}">{{article.title}}</a><br></td>
<td>{{ article.authors}}</td>
<td>{{ article.publicationDate}}</td>
<td>{{ article.journal}}</td>
Expand Down Expand Up @@ -125,24 +125,14 @@
{% for article in manually_curated_articles %}
<tr>
<td>{{ article.topic}}</td>
<td><a href="{{article.url}}">{{article.title}}</a></td>
<td><a href="{{article.url}}">{{article.title}}</a><br></td>
<td>{{ article.authors}}</td>
<td>{{ article.publicationDate}}</td>
<td>{{ article.journal}}</td>
<td>{{ article.citationCount}}</td>
</tr>
{% endfor %}
</tbody>
<tfoot>
<tr>
<th>Topic</th>
<th>Title</th>
<th>Authors</th>
<th>Publication Date</th>
<th>Journal/Conference</th>
<th>Citation count</th>
</tr>
</tfoot>
</table>
</p>

Expand All @@ -159,16 +149,10 @@
{% for article in additional_reading %}
<tr>
<td>{{ article.topic}}</td>
<td><a href="{{article.link}}">{{article.name}}</a></td>
<td><a href="{{article.link}}">{{article.name}}</a><br></td>
</tr>
{% endfor %}
</tbody>
<tfoot>
<tr>
<th>Topic</th>
<th>Title</th>
</tr>
</tfoot>
</table>
</p>

Expand Down

0 comments on commit c3d92b3

Please sign in to comment.