提问人:ahmed barbary 提问时间:11/12/2023 最后编辑:ahmed barbary 更新时间:11/12/2023 访问量:28
数据表过滤器搜索的标题宽度和高度不同?
Data Table Filter search not same width and height of header?
问:
我在 MVC 视图 asp.net 工作。我遇到问题搜索过滤器的列标题高度和宽度不同。
例如,请求 No 列过滤器上方的标题与数据表上标题的宽度和高度不同。
此外,行管理器列搜索过滤器的高度和宽度不相同,行管理器标题。
所以我在设计输入类型文本搜索过滤器上的问题
我尝试如下:
@model IEnumerable<HR.WorkforceRequisition.Models.ResignationRequester>
@{
ViewBag.Title = "PayrollTeam";
Layout = "~/Views/Shared/_LayoutResignation.cshtml";
var color = "white";
}
<style>
thead input {
width: 100%;
border: solid 1px;
}
tfoot input {
width: 100%;
}
</style>
<table id="dtbl" class="table table-bordered table-hover table-striped" style="width:100%;padding-left:5px;
padding-right:7px;">
<thead>
<tr style="background-color: #f2f2f2;">
<th style="border: 1px solid black;">
Request No
</th>
<th style="border: 1px solid black;">
Employee No
</th>
<th style="border: 1px solid black;">
Employee Name
</th>
<th style="border: 1px solid black;">
Request Date
</th>
</tr>
</thead>
<tbody>
@foreach (var item in Model)
{
<tr style="background-color: #f2f2f2;">
<td style="border: 1px solid black;">
@Html.DisplayFor(modelItem => item.RequestNo)
</td>
<td style="border: 1px solid black;">
@Html.DisplayFor(modelItem => item.EmpID)
</td>
<td style="border: 1px solid black;">
@Html.DisplayFor(modelItem => item.EmpName)
</td>
<td style="border: 1px solid black;">
@Html.DisplayFor(modelItem => item.ResignationSubmissionDate)
</td>
}
</tbody>
<tfoot>
<tr>
<th>Request No</th>
<th>Employee No</th>
<th>Employee Name</th>
<th>Request Date</th>
</tr>
</tfoot>
</table>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />
<script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js" type="text/javascript"
language="javascript"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.9/jquery-ui.min.js" type="text/javascript"></script>
<script src="https://code.jquery.com/ui/1.12.0/jquery-ui.min.js"></script>
<script src="https://cdn.datatables.net/1.13.6/js/jquery.dataTables.min.js"></script>
<script>
$(document).ready(function () {
$("#datepicker").datepicker();
new DataTable('#dtbl', {
"dom": 'rtip',
"order": [[0, 'desc']],
initComplete: function () {
$('#dtbl tfoot tr').insertBefore($('#dtbl thead tr'))
this.api()
.columns()
.every(function () {
let column = this;
let title = column.footer().textContent;
let input = document.createElement('input');
input.placeholder = title;
$(input).css("width", "100%"); // Set the input width to 100%
column.footer().innerHTML = ''; // Clear the footer cell
column.footer().replaceChildren(input);
if (title === "Request Date") {
console.log("success request date")
$(this).html('<input type="text" id="datepicker" placeholder="Search ' + title + '" />');
}
else {
$(this).html('<input type="text" placeholder="Search ' + title + '" />');
}
$(column.footer()).html(input);
input.addEventListener('keyup', () => {
if (column.search() !== this.value) {
column.search(input.value).draw();
}
});
});
}
});
});
</script>
用红色包围的输入文本与标题数据表的高度和宽度不一致时出现问题
更新的帖子 :
我可以添加哪个地方
style="padding:0px 0px 0px 0px;margin:0px 0px 0px 0px";
答:
1赞
Ann L.
11/12/2023
#1
作为实验,请尝试将筛选器栏中单元格的样式设置为:
style="padding:0px 0px 0px 0px;margin:0px 0px 0px 0px";
这将是筛选器行单元格的样式,而不是表格本身的样式。
编辑添加:
以下是我的猜测,因为我不知道图书馆。但是您可以尝试更改如下所示的 jquery:datatables
column.footer().innerHTML = ''; // Clear the footer cell
column.footer().replaceChildren(input);
对此:
column.footer().innerHTML = ''; // Clear the footer cell
column.footer().replaceChildren(input);
column.footer().style="padding: 0px 0px 0px 0px;margin: 0px 0px 0px 0px;";
input.style="margin: 0px 0px 0px 0px;";
评论
0赞
ahmed barbary
11/12/2023
在哪个地方添加此样式 jQuery 或者你能给我更多细节
0赞
Ann L.
11/12/2023
@ahmedbarbary我试过了:见上文。
评论
datatables