Search bar on EJS application
I`m curretly working on a project using express and EJS and MySQL as DB. I tried put a search bar on a page that show a list of current events, the events are put on a table using EJS to get data from the database. The counter looks like its working, but the search doesnt hide the not expected results on the table. Any sugestions? (The snippet wont run properly the entire tablesince we dont get the rest of server and code)
$(document).ready(function()
$(".search").keyup(function ()
var searchTerm = $(".search").val();
var listItem = $('.results tbody').children('tr');
var searchSplit = searchTerm.replace(/ /g, "'):containsi('")
$.extend($.expr[':'], 'containsi': function(elem, i, match, array) elem.innerText
);
$(".results tbody tr").not(":containsi('" + searchSplit + "')").each(function(e)
$(this).attr('visible','false');
);
$(".results tbody tr:containsi('" + searchSplit + "')").each(function(e)
$(this).attr('visible','true');
);
var jobCount = $('.results tbody tr[visible="true"]').length;
$('.counter').text(jobCount + ' item(s)');
if(jobCount == '0') $('.no-result').show();
else $('.no-result').hide();
);
);
.results tr[visible='false'],
.no-result
display:none;
.results tr[visible='true']
display:table-row;
.counter
padding:8px;
color:#ccc;
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<!DOCTYPE html>
<html lang="pt-br">
<head>
<meta charset="UTF-8">
<title>TDGEventos</title>
<link rel="icon" href="" title="icon">
<!--CSS -->
<link rel="stylesheet" href="/public/css/bootstrap.css">
<link rel="stylesheet" href="/public/css/style.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src="/public/js/quicksearch.js"></script>
<!--carrega o navbar e o footer-->
<% include layout-nav-footer %>
</head>
<body>
<!--Botao de pesquisa-->
<div class="container">
<div class="row col-lg-12">
<div class="form-group pull-right">
<h2>Eventos</h2>
<input type="text" class="search form-control d-flex" placeholder="Pesquisar eventos">
<span class="container counter pull-right"></span>
</div>
<!--Tabela de resultados-->
<table class="col-md-12 table table-hover table-bordered results">
<thead>
<tr>
<th>Nome</th>
<th>Data de Inicio</th>
<th>Categoria</th>
<th>Premiação</th>
<th class="text-center" colspan="2">Editar</th>
</tr>
<tr class="warning no-result">
<td colspan="5"><i class="fa fa-warning"></i>Sem resultados!</td>
</tr>
</thead>
<tbody>
<% for (var i = 0; i < eventos.length; i++) %>
<tr>
<td><%= eventos[i].nome_evento %></td>
<td><%= eventos[i].data_formatada %></td>
<td><%= eventos[i].categoria %></td>
<td><%= eventos[i].premiacao %></td>
<td hidden><%= eventos[i].idUser = usuario%></td>
<form action="/entrar-evento" method="POST" >
<input style="display:none"name="id" value="<%=eventos[i].id%>">
<td><button id="cadastrar" class="btn btn-dark btn-change6" type="submit">entrar</button></a></td>
</form>
</tr>
<% %>
</tbody>
</table>
</div>
</div>
</body>
</html>
javascript html node.js twitter-bootstrap search
add a comment |
I`m curretly working on a project using express and EJS and MySQL as DB. I tried put a search bar on a page that show a list of current events, the events are put on a table using EJS to get data from the database. The counter looks like its working, but the search doesnt hide the not expected results on the table. Any sugestions? (The snippet wont run properly the entire tablesince we dont get the rest of server and code)
$(document).ready(function()
$(".search").keyup(function ()
var searchTerm = $(".search").val();
var listItem = $('.results tbody').children('tr');
var searchSplit = searchTerm.replace(/ /g, "'):containsi('")
$.extend($.expr[':'], 'containsi': function(elem, i, match, array) elem.innerText
);
$(".results tbody tr").not(":containsi('" + searchSplit + "')").each(function(e)
$(this).attr('visible','false');
);
$(".results tbody tr:containsi('" + searchSplit + "')").each(function(e)
$(this).attr('visible','true');
);
var jobCount = $('.results tbody tr[visible="true"]').length;
$('.counter').text(jobCount + ' item(s)');
if(jobCount == '0') $('.no-result').show();
else $('.no-result').hide();
);
);
.results tr[visible='false'],
.no-result
display:none;
.results tr[visible='true']
display:table-row;
.counter
padding:8px;
color:#ccc;
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<!DOCTYPE html>
<html lang="pt-br">
<head>
<meta charset="UTF-8">
<title>TDGEventos</title>
<link rel="icon" href="" title="icon">
<!--CSS -->
<link rel="stylesheet" href="/public/css/bootstrap.css">
<link rel="stylesheet" href="/public/css/style.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src="/public/js/quicksearch.js"></script>
<!--carrega o navbar e o footer-->
<% include layout-nav-footer %>
</head>
<body>
<!--Botao de pesquisa-->
<div class="container">
<div class="row col-lg-12">
<div class="form-group pull-right">
<h2>Eventos</h2>
<input type="text" class="search form-control d-flex" placeholder="Pesquisar eventos">
<span class="container counter pull-right"></span>
</div>
<!--Tabela de resultados-->
<table class="col-md-12 table table-hover table-bordered results">
<thead>
<tr>
<th>Nome</th>
<th>Data de Inicio</th>
<th>Categoria</th>
<th>Premiação</th>
<th class="text-center" colspan="2">Editar</th>
</tr>
<tr class="warning no-result">
<td colspan="5"><i class="fa fa-warning"></i>Sem resultados!</td>
</tr>
</thead>
<tbody>
<% for (var i = 0; i < eventos.length; i++) %>
<tr>
<td><%= eventos[i].nome_evento %></td>
<td><%= eventos[i].data_formatada %></td>
<td><%= eventos[i].categoria %></td>
<td><%= eventos[i].premiacao %></td>
<td hidden><%= eventos[i].idUser = usuario%></td>
<form action="/entrar-evento" method="POST" >
<input style="display:none"name="id" value="<%=eventos[i].id%>">
<td><button id="cadastrar" class="btn btn-dark btn-change6" type="submit">entrar</button></a></td>
</form>
</tr>
<% %>
</tbody>
</table>
</div>
</div>
</body>
</html>
javascript html node.js twitter-bootstrap search
add a comment |
I`m curretly working on a project using express and EJS and MySQL as DB. I tried put a search bar on a page that show a list of current events, the events are put on a table using EJS to get data from the database. The counter looks like its working, but the search doesnt hide the not expected results on the table. Any sugestions? (The snippet wont run properly the entire tablesince we dont get the rest of server and code)
$(document).ready(function()
$(".search").keyup(function ()
var searchTerm = $(".search").val();
var listItem = $('.results tbody').children('tr');
var searchSplit = searchTerm.replace(/ /g, "'):containsi('")
$.extend($.expr[':'], 'containsi': function(elem, i, match, array) elem.innerText
);
$(".results tbody tr").not(":containsi('" + searchSplit + "')").each(function(e)
$(this).attr('visible','false');
);
$(".results tbody tr:containsi('" + searchSplit + "')").each(function(e)
$(this).attr('visible','true');
);
var jobCount = $('.results tbody tr[visible="true"]').length;
$('.counter').text(jobCount + ' item(s)');
if(jobCount == '0') $('.no-result').show();
else $('.no-result').hide();
);
);
.results tr[visible='false'],
.no-result
display:none;
.results tr[visible='true']
display:table-row;
.counter
padding:8px;
color:#ccc;
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<!DOCTYPE html>
<html lang="pt-br">
<head>
<meta charset="UTF-8">
<title>TDGEventos</title>
<link rel="icon" href="" title="icon">
<!--CSS -->
<link rel="stylesheet" href="/public/css/bootstrap.css">
<link rel="stylesheet" href="/public/css/style.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src="/public/js/quicksearch.js"></script>
<!--carrega o navbar e o footer-->
<% include layout-nav-footer %>
</head>
<body>
<!--Botao de pesquisa-->
<div class="container">
<div class="row col-lg-12">
<div class="form-group pull-right">
<h2>Eventos</h2>
<input type="text" class="search form-control d-flex" placeholder="Pesquisar eventos">
<span class="container counter pull-right"></span>
</div>
<!--Tabela de resultados-->
<table class="col-md-12 table table-hover table-bordered results">
<thead>
<tr>
<th>Nome</th>
<th>Data de Inicio</th>
<th>Categoria</th>
<th>Premiação</th>
<th class="text-center" colspan="2">Editar</th>
</tr>
<tr class="warning no-result">
<td colspan="5"><i class="fa fa-warning"></i>Sem resultados!</td>
</tr>
</thead>
<tbody>
<% for (var i = 0; i < eventos.length; i++) %>
<tr>
<td><%= eventos[i].nome_evento %></td>
<td><%= eventos[i].data_formatada %></td>
<td><%= eventos[i].categoria %></td>
<td><%= eventos[i].premiacao %></td>
<td hidden><%= eventos[i].idUser = usuario%></td>
<form action="/entrar-evento" method="POST" >
<input style="display:none"name="id" value="<%=eventos[i].id%>">
<td><button id="cadastrar" class="btn btn-dark btn-change6" type="submit">entrar</button></a></td>
</form>
</tr>
<% %>
</tbody>
</table>
</div>
</div>
</body>
</html>
javascript html node.js twitter-bootstrap search
I`m curretly working on a project using express and EJS and MySQL as DB. I tried put a search bar on a page that show a list of current events, the events are put on a table using EJS to get data from the database. The counter looks like its working, but the search doesnt hide the not expected results on the table. Any sugestions? (The snippet wont run properly the entire tablesince we dont get the rest of server and code)
$(document).ready(function()
$(".search").keyup(function ()
var searchTerm = $(".search").val();
var listItem = $('.results tbody').children('tr');
var searchSplit = searchTerm.replace(/ /g, "'):containsi('")
$.extend($.expr[':'], 'containsi': function(elem, i, match, array) elem.innerText
);
$(".results tbody tr").not(":containsi('" + searchSplit + "')").each(function(e)
$(this).attr('visible','false');
);
$(".results tbody tr:containsi('" + searchSplit + "')").each(function(e)
$(this).attr('visible','true');
);
var jobCount = $('.results tbody tr[visible="true"]').length;
$('.counter').text(jobCount + ' item(s)');
if(jobCount == '0') $('.no-result').show();
else $('.no-result').hide();
);
);
.results tr[visible='false'],
.no-result
display:none;
.results tr[visible='true']
display:table-row;
.counter
padding:8px;
color:#ccc;
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<!DOCTYPE html>
<html lang="pt-br">
<head>
<meta charset="UTF-8">
<title>TDGEventos</title>
<link rel="icon" href="" title="icon">
<!--CSS -->
<link rel="stylesheet" href="/public/css/bootstrap.css">
<link rel="stylesheet" href="/public/css/style.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src="/public/js/quicksearch.js"></script>
<!--carrega o navbar e o footer-->
<% include layout-nav-footer %>
</head>
<body>
<!--Botao de pesquisa-->
<div class="container">
<div class="row col-lg-12">
<div class="form-group pull-right">
<h2>Eventos</h2>
<input type="text" class="search form-control d-flex" placeholder="Pesquisar eventos">
<span class="container counter pull-right"></span>
</div>
<!--Tabela de resultados-->
<table class="col-md-12 table table-hover table-bordered results">
<thead>
<tr>
<th>Nome</th>
<th>Data de Inicio</th>
<th>Categoria</th>
<th>Premiação</th>
<th class="text-center" colspan="2">Editar</th>
</tr>
<tr class="warning no-result">
<td colspan="5"><i class="fa fa-warning"></i>Sem resultados!</td>
</tr>
</thead>
<tbody>
<% for (var i = 0; i < eventos.length; i++) %>
<tr>
<td><%= eventos[i].nome_evento %></td>
<td><%= eventos[i].data_formatada %></td>
<td><%= eventos[i].categoria %></td>
<td><%= eventos[i].premiacao %></td>
<td hidden><%= eventos[i].idUser = usuario%></td>
<form action="/entrar-evento" method="POST" >
<input style="display:none"name="id" value="<%=eventos[i].id%>">
<td><button id="cadastrar" class="btn btn-dark btn-change6" type="submit">entrar</button></a></td>
</form>
</tr>
<% %>
</tbody>
</table>
</div>
</div>
</body>
</html>
$(document).ready(function()
$(".search").keyup(function ()
var searchTerm = $(".search").val();
var listItem = $('.results tbody').children('tr');
var searchSplit = searchTerm.replace(/ /g, "'):containsi('")
$.extend($.expr[':'], 'containsi': function(elem, i, match, array) elem.innerText
);
$(".results tbody tr").not(":containsi('" + searchSplit + "')").each(function(e)
$(this).attr('visible','false');
);
$(".results tbody tr:containsi('" + searchSplit + "')").each(function(e)
$(this).attr('visible','true');
);
var jobCount = $('.results tbody tr[visible="true"]').length;
$('.counter').text(jobCount + ' item(s)');
if(jobCount == '0') $('.no-result').show();
else $('.no-result').hide();
);
);
.results tr[visible='false'],
.no-result
display:none;
.results tr[visible='true']
display:table-row;
.counter
padding:8px;
color:#ccc;
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<!DOCTYPE html>
<html lang="pt-br">
<head>
<meta charset="UTF-8">
<title>TDGEventos</title>
<link rel="icon" href="" title="icon">
<!--CSS -->
<link rel="stylesheet" href="/public/css/bootstrap.css">
<link rel="stylesheet" href="/public/css/style.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src="/public/js/quicksearch.js"></script>
<!--carrega o navbar e o footer-->
<% include layout-nav-footer %>
</head>
<body>
<!--Botao de pesquisa-->
<div class="container">
<div class="row col-lg-12">
<div class="form-group pull-right">
<h2>Eventos</h2>
<input type="text" class="search form-control d-flex" placeholder="Pesquisar eventos">
<span class="container counter pull-right"></span>
</div>
<!--Tabela de resultados-->
<table class="col-md-12 table table-hover table-bordered results">
<thead>
<tr>
<th>Nome</th>
<th>Data de Inicio</th>
<th>Categoria</th>
<th>Premiação</th>
<th class="text-center" colspan="2">Editar</th>
</tr>
<tr class="warning no-result">
<td colspan="5"><i class="fa fa-warning"></i>Sem resultados!</td>
</tr>
</thead>
<tbody>
<% for (var i = 0; i < eventos.length; i++) %>
<tr>
<td><%= eventos[i].nome_evento %></td>
<td><%= eventos[i].data_formatada %></td>
<td><%= eventos[i].categoria %></td>
<td><%= eventos[i].premiacao %></td>
<td hidden><%= eventos[i].idUser = usuario%></td>
<form action="/entrar-evento" method="POST" >
<input style="display:none"name="id" value="<%=eventos[i].id%>">
<td><button id="cadastrar" class="btn btn-dark btn-change6" type="submit">entrar</button></a></td>
</form>
</tr>
<% %>
</tbody>
</table>
</div>
</div>
</body>
</html>
$(document).ready(function()
$(".search").keyup(function ()
var searchTerm = $(".search").val();
var listItem = $('.results tbody').children('tr');
var searchSplit = searchTerm.replace(/ /g, "'):containsi('")
$.extend($.expr[':'], 'containsi': function(elem, i, match, array) elem.innerText
);
$(".results tbody tr").not(":containsi('" + searchSplit + "')").each(function(e)
$(this).attr('visible','false');
);
$(".results tbody tr:containsi('" + searchSplit + "')").each(function(e)
$(this).attr('visible','true');
);
var jobCount = $('.results tbody tr[visible="true"]').length;
$('.counter').text(jobCount + ' item(s)');
if(jobCount == '0') $('.no-result').show();
else $('.no-result').hide();
);
);
.results tr[visible='false'],
.no-result
display:none;
.results tr[visible='true']
display:table-row;
.counter
padding:8px;
color:#ccc;
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<!DOCTYPE html>
<html lang="pt-br">
<head>
<meta charset="UTF-8">
<title>TDGEventos</title>
<link rel="icon" href="" title="icon">
<!--CSS -->
<link rel="stylesheet" href="/public/css/bootstrap.css">
<link rel="stylesheet" href="/public/css/style.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src="/public/js/quicksearch.js"></script>
<!--carrega o navbar e o footer-->
<% include layout-nav-footer %>
</head>
<body>
<!--Botao de pesquisa-->
<div class="container">
<div class="row col-lg-12">
<div class="form-group pull-right">
<h2>Eventos</h2>
<input type="text" class="search form-control d-flex" placeholder="Pesquisar eventos">
<span class="container counter pull-right"></span>
</div>
<!--Tabela de resultados-->
<table class="col-md-12 table table-hover table-bordered results">
<thead>
<tr>
<th>Nome</th>
<th>Data de Inicio</th>
<th>Categoria</th>
<th>Premiação</th>
<th class="text-center" colspan="2">Editar</th>
</tr>
<tr class="warning no-result">
<td colspan="5"><i class="fa fa-warning"></i>Sem resultados!</td>
</tr>
</thead>
<tbody>
<% for (var i = 0; i < eventos.length; i++) %>
<tr>
<td><%= eventos[i].nome_evento %></td>
<td><%= eventos[i].data_formatada %></td>
<td><%= eventos[i].categoria %></td>
<td><%= eventos[i].premiacao %></td>
<td hidden><%= eventos[i].idUser = usuario%></td>
<form action="/entrar-evento" method="POST" >
<input style="display:none"name="id" value="<%=eventos[i].id%>">
<td><button id="cadastrar" class="btn btn-dark btn-change6" type="submit">entrar</button></a></td>
</form>
</tr>
<% %>
</tbody>
</table>
</div>
</div>
</body>
</html>
javascript html node.js twitter-bootstrap search
javascript html node.js twitter-bootstrap search
asked Nov 12 '18 at 15:05
Altair Todescatto FAltair Todescatto F
2416
2416
add a comment |
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53264922%2fsearch-bar-on-ejs-application%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53264922%2fsearch-bar-on-ejs-application%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown