当前位置: 首页 > 知识库问答 >
问题:

JQuery可更新的搜索和显示条目位于我的表的左侧

薛欣荣
2023-03-14

我已经在我的应用程序中创建了一个Jquery数据表。呈现时,“搜索”和“显示条目”字段位于“我的表”的左侧,如下所示:

我的代码在这里:

@model IEnumerable<Exemptions.ViewModels.ViewModel>
@using PagedList.Mvc;
@{
    ViewBag.Title = "Index";
}

<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.10.20/css/jquery.dataTables.min.css" />
<script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
<script src="~/Scripts/modernizr-2.8.3.js"></script>
<script type="text/javascript" src="https://cdn.datatables.net/1.10.20/js/jquery.dataTables.min.js"></script>

@Html.AntiForgeryToken()



@using (Html.BeginForm(new { @enctype = "multipart/form-data" }))
{
    if (ViewBag.Role == "Officer")
    {
        <div><h1>Please select a Report to view from the Reports Menu</h1></div>
    }
    else if (ViewBag.Role == "PermitAdmin" || ViewBag.Role == "Employee")
    {
        <table class="table" id="id" style="width:75%" border="0" align="center">
            <tr>
                <td colspan="7">
                    <h3>*Search for an Exemption or Create a new Exemption from this page:* </h3>
                    <p class="input-group row">
                        <label class="col-sm-1 col-form-label">
                            <input type="button" value="Create New Owner" class="btn btn-md btn-default " onclick="location.href='@Url.Action("Create", "Owners")'" />
                        </label>
                    </p>
                </td>
            </tr>
        </table>
        <table class="table" id="myTable" style="width:75%" border="1" align="center">
            <thead>
                <tr>
                    <th width="20%">
                        @Html.ActionLink("Land Owner ID", "Index", new { sortOrder = ViewBag.CurrentSort, currentFilter = ViewBag.CurrentFilter })
                    </th>
                    <th width="20%">
                        @Html.ActionLink("First Name", "Index", new { sortOrder = ViewBag.FNameLSortParam, currentFilter = ViewBag.CurrentFilter })
                    </th>
                    <th width="20%">
                        @Html.ActionLink("Last Name", "Index", new { sortOrder = ViewBag.LNameLSortParam, currentFilter = ViewBag.CurrentFilter })
                    </th>
                    <th width="30%">Action</th>
                </tr>
            </thead>
            <tbody>
                @foreach (var item in Model)
                {
                    if (ViewBag.Role == "PermitAdmin")
                    {
                        <tr class="@(item.Owner.RecordDeleted ? "danger" : string.Empty) ">
                            <td>
                                @Html.DisplayFor(modelItem => item.Owner.LandOwnerID)
                            </td>
                            <td>
                                @Html.DisplayFor(modelItem => item.Owner.FNameL)
                            </td>
                            <td>
                                @Html.DisplayFor(modelItem => item.Owner.LNameL)
                            </td>
                            <td align="center">
                                @if (item.Owner.RecordDeleted == false)
                                {
                                    @Html.ActionLink("Edit Landowner", "Edit", new { id = item.Owner.LandOwnerID }) <span> | </span>
                                    @Html.ActionLink("Edit Exemption", "Index", "Permits", new { id = item.Owner.LandOwnerID }, null)
                                }
                                else
                                {
                                    <div>Record Deleted</div>
                                }
                                @if (ViewBag.Role == "PermitAdmin" && item.Owner.RecordDeleted == false)
                                {<span> | </span>@Html.ActionLink("Delete Landowner", "Delete", "Owners", new { id = item.Owner.LandOwnerID }, null)}
                            </td>
                        </tr>
                    }
                    else
                    {
                        <tr>
                            <td>
                                @Html.DisplayFor(modelItem => item.Owner.LandOwnerID)
                            </td>
                            <td>
                                @Html.DisplayFor(modelItem => item.Owner.FNameL)
                            </td>
                            <td>
                                @Html.DisplayFor(modelItem => item.Owner.LNameL)
                            </td>
                            <td align="center">
                                @Html.ActionLink("Edit Landowner", "Edit", new { id = item.Owner.LandOwnerID }) <span> | </span>
                                @Html.ActionLink("Edit Exemption", "Index", "Permits", new { id = item.Owner.LandOwnerID }, null)

                            </td>
                        </tr>
                    }

                }
            </tbody>
        </table>

    }
    else if (ViewBag.Role == "None")
    {
        <div>
            <h2>
                Error! You must be a member of the Officer, Employee, or PermitAdmin groups to view this data!<br />
                <br />Please contact <contact info> to be added to the appropriate group!
            </h2>
        </div>
    }
    else if (ViewBag.Role == "NoUserFound")
    {
        <div>
            <h2>
                Error! We could not find your record in our system!<br />
                <br />Please contact <contact info> to create your account!
            </h2>
            <p><img src="~/Content/images/wildhog.jpeg" /></p>
        </div>
    }

}

<script>
    $(document).ready(function () {
        $('#myTable').DataTable();
    });
</script>

编辑添加:我希望搜索框和显示条目字段在我的表上方。

我需要做什么来解决这个问题?谷歌一点帮助都没有-(

显然,我无法发布此问题,因为与我的邮件文本相比,有太多的代码,因此我提前对此表示歉意:

忽视这一点;这是为了通过过滤器。

Sed ut perspiciatis unde omnis iste natus error sat voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illoinvente veritatis et quasi architecto beatae vitae dicta sunt explicabo。 Nemo enim ipsam voluptatem quia voluptas 坐 aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt。 Neque porro quisquam est, qui dolorem ipsum quia dolor sat amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut laboure et dolore magnam aliquam quaerat voluptatem。 Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit Laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil Molestiae consequatur, velillum qui dolorem eum fugiat quo voluptas nulla pariatur?

你好,Carthax

共有1个答案

廖君昊
2023-03-14

使用以下配置将搜索框移动到右下角:

$('table').DataTable({ "dom": '<"top"i>flrtp<"clear">' });

PS:“底部”flp表示过滤、长度更改和分页将位于底部。

l - Length changing
f - Filtering input
t - The Table!
i - Information
p - Pagination
r - pRocessing
< and > - div elements
<"#id" and > - div with an id
<"class" and > - div with a class
<"#id.class" and > - div with an id and class

参考:https://www.ihbc.org.uk/consultationsdb_new/examples/basic_init/dom.html

 类似资料:
  • 因此,我最近开始学习Android编程,并一直在学习本教程,学习如何在SQLite数据库中插入、更新、删除和查看数据。现在,我还想在这个SQLite数据库中添加一个搜索功能,在这个数据库中,我可以搜索一个名称(我使用的列是name、contact和DOB),如果搜索到的名称与数据库中现有的名称匹配,则在应用程序中显示数据库中的一行/条目。我想这可以以类似于查看/更新数据库的方式来完成,所以我试着用

  • 问题内容: 我想使用jQuery / Java脚本搜索并突出显示文本。 示例HTML 1: 当我搜索字符串“ Good Morning”时,div1和div3中的内容都应突出显示。即。输出html应该是 我使用了插件https://raw.github.com/bartaz/sandbox.js/master/jquery.highlight.js将搜索到的内容包含在span中。但是只有div3高

  • 我正在使用Helm管理Kubernetes集群中的服务,并使用chartmuseum管理我的服务的图表。 在我使用命令添加了repo之后,helm可以与我的repo交互,例如,使用安装可用的图表,或者使用查看所有图表。 现在我面临以下问题: 创建或更新新图表后,我使用命令 上载它。 当我执行时,我希望看到新的图表或图表的更新版本。事实并非如此。此外,当我执行时,我会收到更新的图表的旧版本。

  • 我正在尝试为我的portlet创建一个搜索表单。portlet是一个地址簿应用程序,所有dao和服务都是使用service builder构建的。我想为用户提供一个基本/高级搜索表单(与liferay上的其他表单一样,例如control center中的“用户和组织”)。 我已经实现了所有的逻辑和页面,查看了Lifeay源代码(6.1 GA1),但搜索表单没有以任何方式显示,我将把代码放在这里。

  • 问题内容: 我需要运行以下查询: 但是在执行时会出现错误: 有什么办法吗? 问题答案: 在我看来,进行一些小的更改即可解决此问题? 更改为。因此,您对想要的价值

  • 我知道有AJAX:https://datatables.net/examples/data_sources/server_side.html还有搜索:https://datatables.net/examples/api/multi_filter.html 但我不知道如何将两者结合起来。没错,什么时候。搜索,它按哪个列搜索?如果我想用ADD连接条件呢?

  • 我试图实现与linq文本搜索。我有一个用电子邮件数据填充的消息表。我想能够在消息体中搜索。然而,电子邮件正文很长,我想只显示搜索文本的一小部分,例如,如果我搜索: 奥特 在以下案文中: 知识产权是一种权利,是一种精英的权利,是劳动和财富的暂时性权利。但是,在最低限度上,我们需要一个实验室来进行日常工作。两人或两人在一个无教区的房间里互相指责。除偶尔因疏忽而死亡外,不得因疏忽而导致动物死亡。 结果应

  • 每次文本更改后都会调用onQueryTextChange,但搜索结果只显示一次。当输入和时,RecyclerView显示和(必须按Enter才能启动是否正常?),但当我输入时,显示的项目保持不变。