Я пытаюсь сделать сортировку таблиц возможной с помощью пакета TableSorter 2, найденного здесь: https://mottie.github.io/tablesorter/docs/#Introduction. В идеале я хотел бы получить данные с сервера, а затем обновить их в режиме реального времени или использовать параметр щелчка для сортировки.Сейчас все данные заполняются, но когда вы нажимаете на заголовок, данные не сортируются.Я что-то упускаю из виду?
index.html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<link rel="stylesheet" href="/css/styles.css">
<script src="https://code.jquery.com/jquery-3.3.1.min.js" integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8=" crossorigin="anonymous"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery.tablesorter/2.31.1/js/jquery.tablesorter.min.js"></script>
<title>LTIIT Phone Status</title>
</head>
<body>
<div class='container'>
<table id="techtable"class="table tablesorter">
<thead>
<tr>
<th scope="col">User Name</th>
<th scope="col">Status</th>
<th scope="col">Queue</th>
<th scope="col">Call Status</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
<!-- Horizontal Line Divider -->
<hr>
</div>
<!-- Optional JavaScript -->
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/2.2.0/socket.io.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
<script src="js/index.js"></script>
</body>
</html>
index.js
function getCurrentMembers() {
$.get('memberstatus', (data) => {
data.forEach(element => {
membername = element.username.replace('/','');
membername = membername.replace('-',"");
membername = membername.replace(' ','');
if (element.loggedin == 1) {
$("#techtable tbody").append(`
<tr id="${membername}row">
<td id="${membername}">${element.username}</td>
<td id="${membername}status" class="text-success">Online</td>
<td id="${membername}queue">${element.queue}</td>
<td id="${membername}callstatus">Ready</td>
</tr>`)
} else {
$("#techtable tbody").append(`
<tr id="${membername}row">
<td id="${membername}">${element.username}</td>
<td id="${membername}status" class="text-danger">Offline</td>
<td id="${membername}queue">Offline</td>
<td id="${membername}callstatus">Offline</td>
</tr>`)
}
});
});
$("#techtable").tablesorter({ debug:true });
}
$('document').ready(function(){
getCurrentMembers();
});
Ошибка консоли
Detecting parsers for each column
jquery.tablesorter.min.js:1 No parsers detected!
jquery.tablesorter.min.js:1 Building cache for 0 rows (showing 0 rows in log) and 4 columns (0 ms)
Ответ отСетевая вкладка Chrome для "memberstatus"
[{"username":"TestUser1","loggedin":1,"queue":"FirstResponder"},{"username":"TestUser2","loggedin":0,"queue":"OFFLINE"},{"username":"TestUser3","loggedin":1,"queue":"FirstResponder"},{"username":"TestUser4","loggedin":0,"queue":"TestQueue"},{"username":"TestUser5","loggedin":1,"queue":"TestQueue"}]
server.js Файл NodeJS
//.env file in parent directory that holds variable values - TO BE EXCLUDED FROM GIT!
require('dotenv').config();
//SQLite3 Requirements
var sqlite3 = require('sqlite3').verbose();
var db = new sqlite3.Database('UserStatus.db');
db.serialize(function() {
db.run("CREATE TABLE IF NOT EXISTS users (username TEXT,loggedin INTEGER, queue TEXT)");
});
//Express Web Server Requirements
const express = require('express');
const app = express();
const path = require('path');
const bodyParser = require('body-parser');
//Start the server
const server = app.listen(process.env.Express_Port, () => console.log('Listening on port '+ process.env.Express_Port))
//Express Web uses
app.use(bodyParser.json());
app.use(express.static(path.join(__dirname + '/public')));
//Express Get requests
app.get('/', (req,res) => {
res.sendFile(path.join(__dirname + '/index.html'));
});
app.get('/memberstatus', (req,res) => {
//send back db information
db.all(`SELECT * FROM users`, (err,rows)=>{
if (err) throw err;
res.send(rows);
});
});