Knockout and datatables initComplete option
Knockout and datatables initComplete option
demarily
Posts: 7Questions: 2Answers: 0
Currently I can do this with datatables alone but my goal is to move this over to knockout so that I can use databinding to pass row data to modals. Here are my datatable options...
`var dataTableSettings = {
jQueryUI: true,
processing: true,
paging: true,
retrieve: true,
pagingType: 'full_numbers',
language: {
infoEmpty: 'No paycards found...',
processing: '<i class="fa fa-spinner fa-pulse fa-3x fa-fw"></i>'
},
ajax: {
url: '/Get',
dataSrc: ''
},
initComplete: function (settings, json) {
ko.applyBindings(new PaycardViewModel(json), document.getElementById("main"));
var columnNumber = 13;
// Show tabs for the datatable.
$('#tabs').tabs({
// Handle setting the names of the tabs.
create: function (e, ui) {
$.each($('.assignments-tab'), function () {
setAssignmentTabName(this, table, columnNumber);
});
},
// Handle filtering the datatable based on the tab the user has clicked on.
activate: function (e, ui) {
var status = $(ui.newTab[0].firstChild).data('status');
switch (status) {
case 'All':
table.column(columnNumber).search('').draw();
break;
default:
var regex = '^' + status + '$';
var updatedTable = table.column(columnNumber).search(regex, true, false).draw();
$.each($('.assignments-tab'), function () {
setAssignmentTabName(this, updatedTable, columnNumber);
});
break;
}
}
});
}
}`
My goal is to hide the tabs and show the spinner until the ajax call is complete and the table is drawn. My end goal is to click a row icon that passes the row data to a modal that can process that row data. Thank you for reading this question!
This discussion has been closed.
Answers
Note exactly sure what you are saying but you may be hurting yourself in what it appears you are trying to do.
There is a known bug that affects html, jquery and datatables specifically that if you create the datatable in a hidden (display:none) its going to show up messed up.
I happened to create a demo of this for StackOverflow at http://jsbin.com/dufeli/edit?output
If you look at that demo, tab 2 and three are hidden while tab 1 is not. All tables are created at the same time. Look at the difference between tab one and the other two tabs.
In much abbreviated form, when I created my datatable handler, it went along these lines.
starting with the table container hidden
by the way, for my datatable viewmodel, I use http://coderenaissance.github.io/knockout.viewmodel/ it creates viewmodel down to the cell level. I like it a little bit better than the mapping plugin link on the knockout site.
Thank you @bindrid! Sorry for my lack of explanation but i let me show you an example of my html.
I create the body with the columns: [ data, render ] option. Exception reason is what is counted into each of the tabs. I create one table but use the tabs activate function to search and put the count of each found item into each corresponding tab. The tabs are mapped to the exception reason column. Additionally, the modal is outside the tabs as well. I only use tabs to show each exception reason in the table with search and to display a count of how many of each exception are in the tabs.
Oh and i'm using this custom binder to create the table body.
https://datatables.net/forums/discussion/comment/109990/#Comment_109990
Could you link to the page showing the issue please. I'm not clear on what is actually going wrong with the above.
Allan