I have a table in my site and it has player names and servers. But I need them to be clickable, and needs to have filtering effect.
What I mean is, If you click on player name => the leaderboards will load again as usual and show the servers that the player plays..
and server name => the leaderboards will load again as usual and show the players that play on the server
Another Example: Now let assume I click on username of "ken". After i click on that, the leaderboards only show usernames "ken" and servers that "ken" plays on.
Note: Data from tables are fetch from external JSON file which is https://dayz-n-chill.herokuapp.com/getglobal
The Leaderboard image: image
My Script:
function responseHandler(res) {
res.forEach(function (row, i) {
row.index = i + 1
})
return res
}
function ajaxRequest(params) {
var url = 'https://dayz-n-chill.herokuapp.com/getglobal'
jQuery.get(url, jQuery.param(params.data)).then(function (res) {
params.success(res);
console.log(res);
// this is what i tried so far
var x = $("td").text();
$("td").click(function () {
var rows = $("#tableBody").find("tr").hide();
rows.filter(":contains('$(this).text()')").show();
})
})
}
//
My HTML Code:
<table class="table table-bordered table-hover" data-toggle="table" data-search="true" data-ajax="ajaxRequest"
data-pagination="true" data-height="700" data-response-handler="responseHandler" data-toolbar="#toolbar">
<thead class="thead-dark">
<tr>
<th scope="col" data-field="index" data-sortable="true">Rank</th>
<th scope="col" data-field="userName" data-sortable="true" id="user_name">Username</th>
<th scope="col" data-field="serverName" data-sortable="true">Server Name</th>
<th scope="col" data-field="Kills" data-sortable="true">Kills</th>
<th scope="col" data-field="Deaths" data-sortable="true">Deaths</th>
<th scope="col" data-field="headshot" data-sortable="true">Headshots</th>
<th scope="col" data-field="killStreak" data-sortable="true">Kill Streak</th>
</tr>
</thead>
<tbody id="tableBody">
</tbody>
</table>