簡體   English   中英

如何在laravel會話中存儲tablesorter-filters?

[英]How to store tablesorter-filters in session with laravel?

基本上我有一個帶有過濾器的tablesorter表。 在此處輸入圖片說明

我想實現的是,將對單擊的過濾器進行修改,並且當我重新訪問該頁面時,過濾器將自動應用於表單。

我發現我可以通過laravel的會議來實現這一目標,但是我不知道從哪里開始。

我如何從表分類器中獲取過濾器? 如何將它們存儲到會話中以備后用? 以后如何將它們應用於表分類器?

我使用Laravel 5.3和tablesorter: http ://tablesorter.com/docs/

有人可以讓我走嗎?

任何幫助表示贊賞。

提前致謝。

您可以在初始化表格時告訴表格如何排序。

$(document).ready(function() { 
    // call the tablesorter plugin 
    $("#table").tablesorter({ 
        // set forced sort on the fourth column and i decending order. 
        sortForce: [[0,0]] 
    }); 
}); 

來源: http : //tablesorter.com/docs/example-option-sort-force.html

我將獲得laravel在要排序的列上呈現帶有某種屬性標志的表。

{{-- you don't have to do this in the view but I don't think it really belongs in the controller --}}
@php($columns = ['col1': 'Column heading 1', 'col2': 'Column heading 2')])

<table>
    <thead>
        @foreach($columns as $field => $column_header)
            <th {{ $field === $sort_by ? 'data-sort' : '' }}>{{ $column_header }}</th>
        @endforeach
    </thead>
    <tbody>
        @foreach($row as $item)
            <tr>
                @foreach($columns as $field => $column)
                    <th>{{ $item->get($field) }}</th>
                @endforeach
            </tr>
        @endforeach
    </tbody>
</table>

然后在jQuery中,您可以僅檢查哪個兄弟姐妹具有sort標志。

$(document).ready(function() { 
    var $table = $("#table");
    var sortColumn = $table.find('th[data-sort-by]').prevAll().length;

    $table.tablesorter({ 
        // set forced sort on the fourth column and i decending order. 
        sortForce: [[sortColumn, 0]] 
    }); 
});

然后,您可以對排序順序執行類似的操作。 我認為這是正確的,但文檔實際上是有缺陷的。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM