Создайте постоянство страницы с помощью табулятора - PullRequest
0 голосов
/ 28 мая 2020

Я пытаюсь разрешить пользователю покинуть страницу с Табулятором на нем и вернуться, и он загружает то же представление, что и раньше (включая страницу, на которой он был, фильтры и сортировщики, которые они включили) .

Я пытался заставить его работать с помощью функции сохранения табулятора (как предложено ниже), но получаю сообщение об ошибке: Ошибка разбивки на страницы - запрошенная страница выходит за пределы диапазона 1-1: 3

        //define new tabulator instance
        var table = new Tabulator("#production-data-table", {
            ajaxURL:"scripts/order_status.php?action=fetch_production_data", //ajax URL
            pagination:"remote",
            persistenceMode: "local",
            persistenceID: "production-data",
            persistence: {
                 sort: true, //persist column sorting
                 filter: true, //persist filter sorting
                 group: true, //persist row grouping
                 page: true, //persist page
                 columns: true, //persist columns
            },
            ajaxFiltering:true,
            ajaxSorting:true,
            layout:"fitColumns",
            columns:[
                {title:"Enterprise", field:"Enterprise", sorter:"string", width:100, headerSort:false},
                {title:"Job Number", field:"Job Number", sorter:"number", width:100, headerSort:false},
                {title:"LN #", field:"LN #", sorter:"string", formatter:"html", align:'center', width:80, headerSort:false},
                {title:"Description", field:"Description", sorter:"string", headerSort:false},
                {title:"QTY", field:"QTY", sorter:"string", headerSort:false, align: 'center', width: 40,},
                {title:"AS400 Ship Date", field:"AS400 Ship Date", sorter:"date", align:"center", width:100},
                {title:"Exp. Ship", field:"Est Ship", sorter:"date", align:"center", width:100, headerSort:false},
                //{title:"QC", field:"QC", sorter:"string", formatter:"html", align:'center', width:101, resizable:false, headerSort:false},
                {title:"Pole Barn", field:"Pole Barn", sorter:"string", formatter:"html", align:'center', width:101, resizable:false, headerSort:false},
                {title:"Thermoforming", field:"Thermoforming", sorter:"string", formatter:"html", align:'center', width:101, resizable:false, headerSort:false},
                {title:"Vinyl/Paint", field:"Vinyl/Paint", sorter:"string", formatter:"html", align:'center', width:101, resizable:false, headerSort:false},
                {title:"FA1", field:"Fnl Asmb 1", sorter:"string", formatter:"html", align:'center', width:101, resizable:false, headerSort:false},
                {title:"FA2", field:"Fnl Asmb 2", sorter:"string", formatter:"html", align:'center', width:101, resizable:false, headerSort:false},
                {title:"Crating", field:"Crating", sorter:"string", formatter:"html", align:'center', width:101, resizable:false, headerSort:false},
                {title:"Shipping", field:"Shipping", sorter:"string", formatter:"html", align:'center', width:101, resizable:false, headerSort:false},
                {title:"New", field:"New", visible:false},
                {title:"Revised", field:"Revised", visible:false},
            ],
            ajaxResponse:function(url, params, response) {
                var obj = JSON.parse(JSON.stringify(response)); //parse response
                var array_to_output = obj['tabulator_get_session'];

                console.debug(obj['tabulator_get_session']);
                console.debug(obj['current_page']);

                return response;
            },

            rowFormatter:function(row) {

                var data = row.getData();
                var data = JSON.parse(JSON.stringify(row.getData()));
                var orderNew = data['New'];
                var orderRevised = data['Revised'];

                if ( orderNew == 1 ) {
                    row.getElement().style.backgroundColor = "#69db88";
                    row.getElement().style.fontWeight = "bold";
                }

                if ( orderRevised == 1 ) {
                    row.getElement().style.backgroundColor = "#dbd069";
                    row.getElement().style.fontWeight = "bold";
                    row.getElement().style.fontStyle = "italic";
                }

            },
            placeholder:"No Data Available", //display message to user on empty table

        });

Я бы оставил комментарий вместо того, чтобы редактировать пост. Но сайт мне не позволяет.

1 Ответ

0 голосов
/ 28 мая 2020

Попробуйте использовать следующий кодовый блок для версии 4.6:

        //define new tabulator instance
        var table = new Tabulator("#production-data-table", {
            ajaxURL:"scripts/order_status.php?action=fetch_production_data", //ajax URL
            pagination:"remote",
            persistenceMode: "local",
            persistenceID: "production-data",
            persistence: {
                 sort: true, //persist column sorting
                 filter: true, //persist filter sorting
                 group: true, //persist row grouping
                 page: true, //persist page
                 columns: true, //persist columns
            },
            ajaxFiltering:true,
            ajaxSorting:true,
            layout:"fitColumns",
            columns:[
                {title:"Enterprise", field:"Enterprise", sorter:"string", width:100, headerSort:false},
                {title:"Job Number", field:"Job Number", sorter:"number", width:100, headerSort:false},
                {title:"LN #", field:"LN #", sorter:"string", formatter:"html", align:'center', width:80, headerSort:false},
                {title:"Description", field:"Description", sorter:"string", headerSort:false},
                {title:"QTY", field:"QTY", sorter:"string", headerSort:false, align: 'center', width: 40,},
                {title:"AS400 Ship Date", field:"AS400 Ship Date", sorter:"date", align:"center", width:100},
                {title:"Exp. Ship", field:"Est Ship", sorter:"date", align:"center", width:100, headerSort:false},
                //{title:"QC", field:"QC", sorter:"string", formatter:"html", align:'center', width:101, resizable:false, headerSort:false},
                {title:"Pole Barn", field:"Pole Barn", sorter:"string", formatter:"html", align:'center', width:101, resizable:false, headerSort:false},
                {title:"Thermoforming", field:"Thermoforming", sorter:"string", formatter:"html", align:'center', width:101, resizable:false, headerSort:false},
                {title:"Vinyl/Paint", field:"Vinyl/Paint", sorter:"string", formatter:"html", align:'center', width:101, resizable:false, headerSort:false},
                {title:"FA1", field:"Fnl Asmb 1", sorter:"string", formatter:"html", align:'center', width:101, resizable:false, headerSort:false},
                {title:"FA2", field:"Fnl Asmb 2", sorter:"string", formatter:"html", align:'center', width:101, resizable:false, headerSort:false},
                {title:"Crating", field:"Crating", sorter:"string", formatter:"html", align:'center', width:101, resizable:false, headerSort:false},
                {title:"Shipping", field:"Shipping", sorter:"string", formatter:"html", align:'center', width:101, resizable:false, headerSort:false},
                {title:"New", field:"New", visible:false},
                {title:"Revised", field:"Revised", visible:false},
            ],
            ajaxResponse:function(url, params, response) {
                var obj = JSON.parse(JSON.stringify(response)); //parse response
                var array_to_output = obj['tabulator_get_session'];

                console.debug(obj['tabulator_get_session']);
                console.debug(obj['current_page']);

                return response;
            },

            rowFormatter:function(row) {

                var data = row.getData();
                var data = JSON.parse(JSON.stringify(row.getData()));
                var orderNew = data['New'];
                var orderRevised = data['Revised'];

                if ( orderNew == 1 ) {
                    row.getElement().style.backgroundColor = "#69db88";
                    row.getElement().style.fontWeight = "bold";
                }

                if ( orderRevised == 1 ) {
                    row.getElement().style.backgroundColor = "#dbd069";
                    row.getElement().style.fontWeight = "bold";
                    row.getElement().style.fontStyle = "italic";
                }

            },
            placeholder:"No Data Available", //display message to user on empty table
            //ajaxLoaderError:"<div>New Error new error new error</div>",
            dataLoaded: function(data) {
                table.setPage(<?=$_SESSION['tabulator_get']['pagination']['current_page']?>);
            },

        });

Это должно позволить вам сохранить состояние таблицы в localStorage для удобства использования.

Ссылка на документацию: http://tabulator.info/docs/4.6/persist

EDIT:

После некоторого просмотра блока кода кажется, что вам не хватает некоторых необходимых аргументов для удаленной разбивки на страницы. См. Документы здесь: http://tabulator.info/docs/4.6/page#remote

...