繁体   English   中英

jQuery搜索仅搜索其上的页面

[英]jQuery search only searching the page its on

我有laravel数据,使用laravel默认默认分页器进行分页,如下所示。

调节器

$applications = Application::onlyTrashed()->latest()->paginate(25);
return view('index', compact('applications'));

桌子是我的刀片模板是这样的

<label for="kwd_search">Search:</label> <input type="text" id="kwd_search" value=""/>
<table class="table table-striped table-bordered table-hover" id="my-table1">
    <thead>
        <tr class="header">
            <th>{{ trans('crud.users.id') }}</th>
            <th>{{ trans('Name') }}</th>
            <th>{{ trans('Email') }}</th>
            <th>{{ trans('Country') }}</th>
            <th>{{ trans('Contact No') }}</th>
            <th>{{ trans('counsellor') }}</th>
            <th>{{ trans('Submitted On') }}</th>
            <th>{{ trans('Status') }}</th>
            <th>{{ trans('crud.actions') }}</th>
        </tr>
    </thead>
    <tbody>
        @foreach ($archivedApplications as $row)
        <tr>
            <td>{!! $row->id !!}</td>
            <td>{!! $row->name ?: 'No Name Provided'!!}</td>
            <td>{!! $row->email !!}</td>
            <td>{!! $row->country['name'] ?: 'No Country Provided' !!}</td>
            <td>{!! $row->contact_no ?: 'No Number Provided' !!}</td>
            <td>{!! ((isset($row->counsellor->name))?$row->counsellor->name:'') !!}</td>
            <td>{!! $row->created_at !!}</td>

            <!-- additional td -->
            <td>
                <span class="blockify-button btn-warning">{!! trans('Archived') !!}</span>
            </td>
        </tr>
        @endforeach
    </tbody>
</table>

下面是我的JS搜索。 它当前仅搜索当前页面,而不仅仅是我所在的页面。

<script>
$(document).ready(function(){
    // Write on keyup event of keyword input element
    $("#kwd_search").keyup(function(){
        // When value of the input is not blank
        var term=$(this).val()
        if( term != "")
        {
            // Show only matching TR, hide rest of them
            $("#my-table1 tbody>tr").hide();
            $("#my-table1 td").filter(function(){
                   return $(this).text().toLowerCase().indexOf(term ) >-1
            }).parent("tr").show();
        }
        else
        {
            // When there is no input or clean again, show everything back
            $("#my-table1 tbody>tr").show();
        }
    });
});

</script>

不确定“当前”页面和“我所在的页面”之间有什么区别,但是如果您不仅要过滤呈现的表,还要过滤整个数据库,则应发送带有#kwd_search内容的ajax请求,并使用它来进行sql请求,接收结果列表。 可能更好的解决方案是在页面加载时从DB槽ajax获取整个列表,将其拆分并使用js框架呈现表。 在这种情况下,您可以处理整个数据,而无需不必要的ajax请求。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM