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;
});
}
});
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