function Lead(data){
this.id = data.id;
this.name = ko.observable(data.name);
this.number = ko.observable(data.mobile);
this.email = ko.observable(data.email);
this.return_date = ko.observable(data.return_date);
this.advert = ko.observable(data.advert);
this.date_enquired = ko.observable(data.date);
}
function leadView(){
var self = this;
self.leads = ko.observableArray([]);
$.getJSON('ajax/leads.php', function(data){
var mapped = $.map(data, function(info){
return new Lead(info);
});
self.leads(mapped);
var dt = $('#lead-table').DataTable({
dom: "tip",
ordering: false,
bProcessing: true,
data: self.leads(),
columns: [
{data: 'name()' },
{data: 'number()' },
{data: 'email()' },
{data: 'return_date()' },
{data: 'advert()' },
{data: 'date_enquired()' }
]
});
});
self.update = function(){
$.getJSON('leads.php', function(data){
var mapped = $.map(data, function(info){
return new Lead(info);
});
self.leads(mapped);
});
}
}
var DataLeadView = new leadView();
window.setInterval(DataLeadView.update, 5000);
ko.applyBindings(DataLeadView);
i have this code which is printing out my table just fine using Knockout JS and DataTables, i have a counter which shows the total number of leads.
then i run my function to update the leads() observableArray; that updates the counter but not the table so my question is how do i get the table to add the row thats just been added to the array?
dt.draw()if you want to cleardt.clear().draw(). cheers