page.JumpToData() not working :(

page.JumpToData() not working :(

nickardonickardo Posts: 5Questions: 1Answers: 0

I'm getting the following error ("Cannot read property API of undefined") when I try to use JumpToData(). Any ideas what I'm doing wrong?

ERROR
jquery-3.3.1.min.js:2 Uncaught TypeError: Cannot read property 'Api' of undefined
at HTMLDocument.<anonymous> (<anonymous>:304:33)
at l (jquery-3.3.1.min.js:2)
at c (jquery-3.3.1.min.js:2)

CODE


<link href="https://cdn.datatables.net/1.10.12/css/jquery.dataTables.min.css" rel="stylesheet" media="screen">

TLO.JQ(document).ready(function () {

        jQuery.fn.dataTable.Api.register('page.jumpToData()', function (data, column) {
            var pos = this.column(column, { order: 'current' }).data().indexOf(data);

            if (pos >= 0) {
                var page = Math.floor(pos / this.page.info().length);
                this.page(page).draw(false);
            }

            return this;
        });

        TLO.Handler("#LettersForm", "LOAD_ENTRIES", null, (formName, data) => {
            TLO.JQ('#custLettEntry').val(data["EntryLength"]);
            TLO.Handler("#LettersForm", "LOAD_COLUMN_ORDER", null, (formNamek, data) => {
                TLO.JQ("#columnOrder").val(data["ColumnOrder"]);
                try {
                    TLO.CustomLettersGrid = TLO.JQ('#LettersForm .tlotable').DataTable({
                        "columnDefs": [
                            { "type": "date", "targets": "columnDate" }],
                        paging: true,
                        pagingType: "full_numbers",
                        searching: false,
                        select: true,  
                        dom: 't<"bottom"lp>',
                        colReorder: true,
                        stateSave: true,
                        stateSaveCallback: function (settings, data) {
                            debugger

                            let lengthValue;
                            if (data.length) {
                                TLO.JQ('#custLettEntry').val(data.length)
                                lengthValue = data.length
                            } else {
                                lengthValue = TLO.JQ('#custLettEntry').val()
                            }

                            let columnOrder;
                            if (data.ColReorder) {
                                TLO.JQ('#columnOrder').val(data.ColReorder)
                                columnOrder = data.ColReorder
                            } else {
                                columnOrder = TLO.JQ('#columnOrder').val()
                            }
                            data.length = "";
                            data.order = "";
                            localStorage.setItem('DataTables_' + settings.sInstance, JSON.stringify(data))
                            TLO.Handler("#LettersForm", "SAVE_ENTRIES", lengthValue)
                            TLO.Handler("#LettersForm", "SAVE_COLUMN_ORDER", columnOrder)
                        },
                        stateLoadCallback: function (settings) {
                            return JSON.parse(localStorage.getItem('DataTables_' + settings.sInstance))
                        },
                        fixedHeader: {
                            footer: false
                        },
                        scrollX: true,    
                        scrollX: true,
                        bInfo: false,
                        width: '100%',
                        autoWidth: true,
                        initComplete: function (settings, json) {
                            debugger
                            TLO.Loading(false);
                            let lengthValue = TLO.JQ('#custLettEntry').val();
                            TLO.JQ('#LettersForm .tlotable').DataTable().page.len(lengthValue).draw();
                            var table = TLO.Tbl('LettersForm');
                            table.column(0).visible(false);
                            TLO.JQ(`#LettersForm`).find(`#MainDiv`).css(`visibility`, `visible`);
                        },  
                        order: []
                    });

                } catch (e) {
                    debugger
                    TLO.Loading(false);
                    TLO.JQ(`#LettersForm`).find(`#MainDiv`).css(`visibility`, `visible`);
                }
            })
        })

        TLO.CustomLettersGrid.page.jumpToData("LetterTime", 1);

    });

Answers

  • colincolin Posts: 15,240Questions: 1Answers: 2,599

    My guess is it's because it's outside of the try block on line 16 - try moving it to line 73.

    If that doesn't help, we're happy to take a look, but as per the forum rules, please link to a test case - a test case that replicates the issue will ensure you'll get a quick and accurate response. Information on how to create a test case (if you aren't able to link to the page you are working on) is available here.

    Cheers,

    Colin

This discussion has been closed.