knockoutjs and datatables
knockoutjs and datatables
anybody used these two together? i'm trying to figure out how to dynamically populate the datatables with knockoutjs observables.
let me give a pseudo example:
[code]
//i'll create an instance of a datatable and tell it what columns to use
$('.data-table').dataTable({
"bJQueryUI": true,
"sPaginationType": "full_numbers",
"sDom": '<""l>t<"F"fp>',
"aoColumns": [
{ 'mData': 'id' },
{ 'mData': 'vendor' }
]
});
//here's an object - called submission
function submission(data) {
this.id = ko.observable(data.id);
this.vendor = ko.observable(data.vendor);
}
//i want to populate the datatable with an array of submission objects, so i create an observable array of submissions
var submissions = ko.observableArray([]);
//create an object (let's assume that id and vendor are observables)
var sub = new submission({
id: this.id(),
vendor: this.vendor()
});
//add the object to the array
this.submissions.push(sub);
//now i want to add the array to the datatable
// BUT HOW?????????????
//i've tried this: and other variations
$('.data-table').dataTable.fnAddData(this.submissions());
// (doesn't work)
[/code]
let me give a pseudo example:
[code]
//i'll create an instance of a datatable and tell it what columns to use
$('.data-table').dataTable({
"bJQueryUI": true,
"sPaginationType": "full_numbers",
"sDom": '<""l>t<"F"fp>',
"aoColumns": [
{ 'mData': 'id' },
{ 'mData': 'vendor' }
]
});
//here's an object - called submission
function submission(data) {
this.id = ko.observable(data.id);
this.vendor = ko.observable(data.vendor);
}
//i want to populate the datatable with an array of submission objects, so i create an observable array of submissions
var submissions = ko.observableArray([]);
//create an object (let's assume that id and vendor are observables)
var sub = new submission({
id: this.id(),
vendor: this.vendor()
});
//add the object to the array
this.submissions.push(sub);
//now i want to add the array to the datatable
// BUT HOW?????????????
//i've tried this: and other variations
$('.data-table').dataTable.fnAddData(this.submissions());
// (doesn't work)
[/code]
This discussion has been closed.