0

I create table using dynatable. But i get error:

TypeError: dyna.features is undefined

    $(document).ready(function () {
        gettableupdates();
        var dyna;
        function gettableupdates() {
            $.getJSON('ajax_data.json',
                function (data) {
                    dyna = $('#product-table').dynatable({
                        dataset: {
                            records: data
                        }
                    }).data('dynatable');
                    dyna.features.paginate.recordCount = false;
                    dyna.features.paginate.perPageSelect = false;
                });
        }
    });
user3794273
  • 91
  • 1
  • 1
  • 11

1 Answers1

1

A console.log of the dyna variable shows the following:

{   
    $element: [table#dyno-table, context: table#dyno-table]
    dom: Dom {update: ƒ}
    domColumns:DomColumns {initOnLoad: ƒ, init: ƒ, getFromTable: ƒ, add: ƒ, remove: ƒ, …}
    element : table#dyno-table
    inputsSearch : InputsSearch {initOnLoad: ƒ, init: ƒ, create: ƒ, attach: ƒ}
    paginationLinks : PaginationLinks {initOnLoad: ƒ, init: ƒ, create: ƒ, buildLink: ƒ, attach: ƒ}
    paginationPage : PaginationPage {initOnLoad: ƒ, init: ƒ, set: ƒ}
    paginationPerPage : PaginationPerPage {initOnLoad: ƒ, init: ƒ, create: ƒ, attach: ƒ, set: ƒ}
    processingIndicator : ProcessingIndicator {init: ƒ, create: ƒ, position: ƒ, attach: ƒ, show: ƒ, …}
    queries : Queries {initOnLoad: ƒ, init: ƒ, add: ƒ, remove: ƒ, run: ƒ, …}
    records : Records {initOnLoad: ƒ, init: ƒ, updateFromJson: ƒ, sort: ƒ, paginate: ƒ, …}
    recordsCount : RecordsCount {initOnLoad: ƒ, init: ƒ, create: ƒ, attach: ƒ}
    settings : {features: {…}, table: {…}, inputs: {…}, dataset: {…}, writers: {…}, …}
    sorts : Sorts {initOnLoad: ƒ, init: ƒ, add: ƒ, remove: ƒ, clear: ƒ, …}
    sortsHeaders : SortsHeaders {initOnLoad: ƒ, init: ƒ, create: ƒ, removeAll: ƒ, removeOne: ƒ, …}
    state : State {initOnLoad: ƒ, init: ƒ, push: ƒ, pop: ƒ}
    __proto__ : Object
}

This is the output in the Chrome Dev tools formatted nicely to show what the object key names are. As you can see, there is no direct access to features through the top level object. It is, however, inside settings.

So dyna.features is undefined

but

dyna.settings.features is an object which is probably what you are looking for.

So you just need to change the following lines from:

dyna.features.paginate.recordCount = false;
dyna.features.paginate.perPageSelect = false;

to

dyna.settings.features.paginate.recordCount = false;
dyna.settings.features.paginate.perPageSelect = false;

Update

Actually, I am not sure what you are trying to do but the above example will prevent the error but it may not get you the desired results. If your intention was to disable pagination and record counting then it won't work. You have to define those features on initialization. You can do this by adding in a features object with some properties like so:

// ...previous code
dyna = $('#product-table').dynatable({
    dataset: {
        records: data
    },
    features: {
        recordCount: false,
        perPageSelect: false,
    }
}).data('dynatable');
//... after code
JoeMoe1984
  • 1,912
  • 3
  • 21
  • 31
  • I saw this solution but in the next step I want to use "Querying". I want to use the properties because of such solutions: - dynatable.queries.remove ("id"); - dynatable.queries.add ("id", value); they give the same error – user3794273 Sep 29 '17 at 18:54
  • That doesn't matter. Your initial problem was solved. You should ask that as a separate question if you are having other difficulties. You wanted to know why dyna.features returned undefined and I answered that. If that fixed your initial error then this should be marked as solved. – JoeMoe1984 Sep 29 '17 at 19:08
  • Also, if you are having the same error on another part of your code then repeat the steps used in this answer to solve it first. Then ask another question if you still can't fix it with details of the steps you tried to resolve it and the details of what you are trying to do. – JoeMoe1984 Sep 29 '17 at 19:10
  • Unfortunately not. dyna.settings.features returns me undefined – user3794273 Sep 29 '17 at 19:13
  • Update your question with the console log I mentioned earlier. You provided a weird output in the comments. See how mine looks? Try to get the same output. Use the dev tools "console" section in Chrome (or whatever browser you use) to get the console.log output and paste that in your question details. With your code I have access to those settings. So it could be something else. – JoeMoe1984 Sep 29 '17 at 19:18