Datatables with jquery UI Tabs
Datatables with jquery UI Tabs
dyapasrikanth
Posts: 20Questions: 0Answers: 0
I have 3 tabs in my application, where each tab displays datatable from the server.
When i click on the second tab it displays only the data of the table with out styles and even search box also.
What's the Problem
[code]
$(function() {
$("#tabs").tabs();
});
<%
String staffId = null;
if(request.getUserPrincipal().getName().equals("admin"))
staffId = request.getParameter("staffId").trim();
else
staffId = request.getRemoteUser();
%>
Staff IDs: <%=staffId%>
UnAttended
Attended
Pending
Closed
When i click on the second tab it displays only the data of the table with out styles and even search box also.
What's the Problem
[code]
$(function() {
$("#tabs").tabs();
});
<%
String staffId = null;
if(request.getUserPrincipal().getName().equals("admin"))
staffId = request.getParameter("staffId").trim();
else
staffId = request.getRemoteUser();
%>
Staff IDs: <%=staffId%>
UnAttended
Attended
Pending
Closed
This discussion has been closed.
Replies
Allan
problem not solved.
first tab displaying datatable successfully but the next tab onward it doesn't display the datatable correctly but it displays table data correctly
first tab displaying correctly but when i navigate from one tab to another datatable is not going to re-initialize.
There is no javascript error
Allan
yes i am initializing the table before the data loaded from the server.
Allan
It is very urgent, i am unable to do the next things. Because the data in the tables are loaded dynamically from the server. That means Tab loads datatable without body and then datatable calls the server functionality to load the table data.
Initial tab works fine but only once. when i navigate back to first tab the table header alignment is disturbed.
I don't know much about jQuery UI tabs, but if there is an iframe option, you might want to look into that.
Allan
So what I did is, each time a tab is shown I auto refresh the iframe and it displays perfectly. It's kind of a hack, but works for my case.
style="overflow-x:hidden;overflow-y:auto;width:650px"
replace 650px
Here are a few of the highlights to our approach that we've come up with (code below is greatly simplified and might need some tweaking):
- bRetrieve is set to true for datatable initialization
- we use the following settings as defaults for Jquery UI tabs:
[code]
$.extend($.ui.tabs.prototype.options, {
cache : true, // Only load content for an AJAX tab once
load : loadTabBase,
show : loadTabBase
});
[/code]
- in the load and show events for the tabs, we call the following:
[code]
var loadTabBase = function(event, ui) {
// Only select datatables that have a tbody -- this prevents selecting the headers when sScrollY is set
var tables = $(ui.panel).find(".dataTable").has("tbody");
tables.each(function()
{
// resize the table
var tb = $(this);
var dt = tb.dataTable();
if(dt.length > 0) {
dt.fnAdjustColumnSizing();
}
});
};
[/code]
- for our individual sets of tabs we may override the loadTab function to do something like the following:
[code]
var loadTabSpecific = function(event, ui) {
// Call base
loadTabBase(event, ui);
// Look for uninitialized datatables
var tb = $(".my-datatable-class", params.tab).not(".dataTable");
if(tb.length == 0) {
return;
}
// Initialize the datatable
dt = tb.dataTable(getDatatableOptions());
};
[/code]
As a note, though, our approach is working great in IE8 (in standards mode), but the call to get the datatable in loadTabBase is resulting in the table being reinitialized rather than returned in IE7 compatability mode.