Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tuning module page #26

Merged
merged 2 commits into from
Aug 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions website_generator/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
!/website_source/index.Rmd
!/website_source/dummy.bib
!/website_source/images/*
!/website_source/selectKeyword.js

# History files
.Rhistory
Expand Down
2 changes: 1 addition & 1 deletion website_generator/website_source/index.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ DT::datatable(nassa_table_print,
```
</div>

<script src='../js/selectKeyword.js'></script>
<script src='selectKeyword.js'></script>

<table class='legend'>
<tr>
Expand Down
66 changes: 66 additions & 0 deletions website_generator/website_source/selectKeyword.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
$(document).ready(function() {
// Verify the table ID by logging it
//console.log('Table ID:', '#nassa_table_container_table');

// DataTable instance using the correct ID
var table = $('#nassa_table_container_table').DataTable();

// Check if the table is correctly initialized
//if (table) {
// console.log('DataTable initialized successfully.');
//} else {
// console.log('Failed to initialize DataTable.');
//}

const searchInput = document.querySelector('#nassa_table_container input[type="search"]');
const keywordColumnIndex = 6; // Assuming "Keywords" is the 7th column (0-indexed)
const event = new Event('input', { bubbles: true });

// Add click event listener to each badge
$(document).on('click', '.badge', function() {
var keyword = $(this).data('keyword');
//console.log('Badge clicked, keyword:', keyword); // Debugging output

// Apply the search filter with the keyword
if (keyword) {
//table.columns().search(keyword).draw();
// Select the search input within the nassa_table_container


// Check if the search input exists
if (searchInput) {
// Set the value to your desired string
searchInput.value = keyword;

// Apply a custom search to the "Keywords" column
table.column(keywordColumnIndex).search(function(data, type) {
// Check if the data in the "Keywords" column contains the exact keyword
const regex = new RegExp(`(^|,\\s*)${searchTerm}(,|$)`, 'i');
return regex.test(data);
});

// Trigger the input event to apply the search filter immediately
searchInput.dispatchEvent(event);

table.draw(); // Redraw the table to apply the custom filter

//console.log('✔️ Search input value has been set successfully!');
} else {
//console.error('❗ Search input not found within the specified container.');
}

searchInput.value = ''
}
});

// Optional: Add a button to reset the search filter
//$('.legend').append('<button id="resetFilter" style="margin-left: 20px;">Show All</button>');
// Reset the search filter when 'Show All' is clicked
$(document).on('click', '#resetFilter', function() {
//console.log('Reset button clicked.'); // Debugging output
searchInput.value = ''
searchInput.dispatchEvent(event);
//table.search('').draw();
});
});

Loading