如何使用yajrabox数据表按ID过滤表

时间:2018-09-20 03:29:25

标签: laravel datatables

将标准表转换为Ajax数据表。如何获取Ajax数据表以对特定ID进行过滤。

示例:“标签”显示视图,其中表格显示与所选“标签显示”视图关联的所有兴趣(联系人)。

<div role="tabpanel" class="tab-pane active" id="interests">
<table class="table table-bordered table-striped {{ count($interests) > 0 ? 'datatable' : '' }}">
<thead>
    <tr>
        <th>@lang('global.interests.fields.firstname')</th>
                    <th>@lang('global.interests.fields.lastname')</th>
                    <th>@lang('global.interests.fields.address')</th>
                    <th>@lang('global.interests.fields.phone')</th>
                    <th>@lang('global.interests.fields.email')</th>
                    <th>@lang('global.interests.fields.interest-tags')</th></tr>
</thead>`




<tbody>
    @if (count($interests) > 0)
        @foreach ($interests as $interest)
            <tr data-entry-id="{{ $interest->id }}">
                <td field-key='firstname'>{{ $interest->firstname }}</td>
                            <td field-key='lastname'>{{ $interest->lastname }}</td>
                            <td field-key='address'>{{ $interest->address }}</td>
                            <td field-key='phone'>{{ $interest->phone }}</td>
                            <td field-key='email'>{{ $interest->email }}</td>
                            <td field-key='interest_tags'>
                                @foreach ($interest->interest_tags as $singleInterestTags)
                                    <span class="label label-info label-many">{{ $singleInterestTags->interest_tags }}</span>
                                @endforeach
                            </td>

原始内容-data-entry-id =“ {{$ interest-> id}}” –过滤我的兴趣列表,仅显示与我选择的Tag show视图关联的那些。如何使用Ajax数据表完成相同的操作?

以下是使用数据表的同一视图:

<div class="panel-body table-responsive">
    <table class="table table-bordered table-striped ajaxTable @can('interest_delete') @if ( request('show_deleted') != 1 ) dt-select @endif @endcan">
        <thead>
        <tr>


            <th>@lang('global.interests.fields.firstname')</th>
            <th>@lang('global.interests.fields.lastname')</th>
            <th>@lang('global.interests.fields.address')</th>
            <th>@lang('global.interests.fields.phone')</th>
            <th>@lang('global.interests.fields.email')</th>
            <th>@lang('global.interests.fields.interest-tags')</th>
        </tr>
        </thead>
    </table>
</div>` 


@section('javascript')
        @include('csvImport.modal', ['model' => 'Interest'])
        <script>
            @can('interest_delete')
                    @if ( request('show_deleted') != 1 ) window.route_mass_crud_entries_destroy = '{{ route('admin.interests.mass_destroy') }}'; @endif
            @endcan
            $(document).ready(function () {
                window.dtDefaultOptions.ajax = '{!! route('admin.interests.advanced') !!}?show_deleted={{ request('show_deleted') }}';
                window.dtDefaultOptions.stateSave = true;
                //window.dtDefaultOptions.scrollX = true;
                //window.dtDefaultOptions.scrollY = '50vh';
                window.dtDefaultOptions.scrollCollapse = true;
                window.dtDefaultOptions.columnDefs = [{orderable: false, targets: 10}]
                window.dtDefaultOptions.columns = [@can('interest_delete')
                    @if ( request('show_deleted') != 1 )
                {data: 'massDelete', name: 'id', searchable: false, sortable: false},
                        @endif
                        @endcan{data: 'firstname', name: 'firstname'},
                    {data: 'lastname', name: 'lastname'},
                    {data: 'address', name: 'address'},
                    {data: 'email', name: 'email'},
                    {data: 'interest_tags.interest_tags', name: 'interest_tags.interest_tags'},


                    {data: 'actions', name: 'actions', searchable: false, sortable: false}
                ];
                processAjaxTables();
            });
        </script>
    @endsection`

在这种新布局中,我如何以及在何处包括等效的id过滤器,该过滤器与原始表中的-data-entry-id =“ {{$ interest-> id}}”“具有相同的基本功能?因为现在我可以获得全部兴趣表的内容,而不只是我在“标签显示”视图中查看的已分配给标签的内容。

0 个答案:

没有答案