我有一个包含列名的表(FirstName,LastName,Age,Profession,Salary)。 我有3个搜索框即(FirstName,LastName,Salary)。
如果我输入名称,请说" xyz"在FirstName文本框中,然后是值" xyz"应该只在FirstName列中搜索。同样,如果我输入值" abcd"在姓氏搜索框中然后是值" abcd"应该只在lastname列中搜索。
如何使用jquery数据表完成上述功能。
示例代码 //搜索文本框
<html><body>
<div>
<table width='100%'>
<tr>
<td >First Name:</td> <td id='fname'><input type= "text"></td>
</tr>
<tr ><td >Last name:</td>
<td id="lname"><input type= "text"></td>
</tr>
<tr ><td >Age:</td>
<td id="age"><input type= "text"></td>
</tr>
<tr ><td >Profession:</td>
<td id='prof'><input type= "text"></td>
</tr>
<tr ><td >Salary:</td>
<td id='sal'><input type= "text"></td>
</tr>
</table>
</div>
//表
<table id="example" class="display" cellspacing="0" width="100%">
<thead>
<tr>
<th>First Name</th>
<th>Last Name</th>
<th>Age</th>
<th>Profession</th>
<th>Salary</th>
</tr>
</thead>
<tbody>
<tr>
<td>Tiger Nixon</td>
<td>Nixon</td>
<td>61</td>
<td>Engineer</td>
<td>320,800</td>
</tr>
<tr>
<td>Garrett</td>
<td>Winters</td>
<td>63</td>
<td>Accountant</td>
<td>170,750</td>
</tr>
<tr>
<td>Ashton</td>
<td>Cox</td>
<td>66</td>
<td>Junior Technical Author</td>
<td>86,000</td>
</tr>
<tr>
<td>Cedric </td>
<td>Kelly</td>
<td>22</td>
<td>Senior Javascript Developer</td>
<td>433,060</td>
</tr>
<tr>
<td>Charde </td>
<td>Marshall</td>
<td>36</td>
<td>Regional Director</td>
<td>470,600</td>
</tr>
<tr>
<td>Haley </td>
<td>Kennedy</td>
<td>43</td>
<td>Senior Marketing Designer</td>
<td>313,500</td>
</tr>
</tbody>
</table>
</body>
</html>
// Jquerycode
$(example).dataTable().
columnFilter({aoColumns:[
{ sSelector: "#fname"},
{ sSelector: "#lname" },
null
null,
{sSelector: "#sal"},
]}
);
答案 0 :(得分:1)
WITH a
as
(
select colid,coldate
from cal_3month
group by colid,coldate
),
b
as
(
select colid,SUM(colvalue) as sumvalue
from cal_3month td
WHERE extract('month' from td.coldate) between extract('month' from now() - interval '3 month') and extract('month' from now() - interval '1 month')
and extract('year' from td.coldate) = extract('year' from now()) --and td.st_exchng = 'NSE'
group by td.coldate,td.colid
order by td.coldate desc
)
,
c
as
(
SELECT a.colid,string_agg((extract('year' from a.coldate)::varchar||extract('month' from a.coldate)::varchar)::varchar,',') as dt,
string_agg(b.sumvalue::varchar,',') as vl
from a
inner join b
on a.colid = b.colid
group by a.colid
)
select c.colid,hstore(c.dt,c.vl)
from c;