One table - different sources from different buttons
One table - different sources from different buttons
Scone
Posts: 1Questions: 1Answers: 0
Hi,
I have two buttons which get data from ajax and pass it to function to build the table. This is the code:
function getContactData() {
$.ajax({
type: "POST",
url: "AjaxData.aspx/getContactdata",
contentType: "application/json; charset=utf-8",
data: '{}',
dataType: "json",
success: function (msg) {
displayData(msg);
},
failure: function (response) {
alert(response.d);
}
});
}
function getClientData() {
$.ajax({
type: "POST",
url: "AjaxData.aspx/getClientdata",
contentType: "application/json; charset=utf-8",
data: '{}',
dataType: "json",
success: function (msg) {
displayData(msg, "AjaxData.aspx/getClientdata", "clients");
},
failure: function (response) {
alert(response.d);
}
});
}
function displayData( dataToDisplay, url, myType) {
var _data = dataToDisplay.d;
var _cols = [];
var _tableHeaders = "<tr>"
for (var key in _data[0]) {
//alert(' name=' + key + ' value=' + p[key]);
_cols.push(key);
}
$.each(_cols, function (i, val) {
_tableHeaders += "<th>" + val + "</th>";
});
_tableHeaders += "</tr>"
$("#tblTestJSON_th").empty();
$("#tblTestJSON_th").append(_tableHeaders);
var _tableRows;
$.each(_data, function (i, _dr) {
var _tableRow = '<tr>';
$.each(_dr, function (x, _item) {
_tableRow += '<td>' + _item + '</td>';
});
_tableRow += '</tr>'
_tableRows += _tableRow;
});
$("#tblTestJSON_tb").empty();
$("#tblTestJSON_tb").append(_tableRows);
if ($.fn.dataTable.isDataTable('#tblTestJSON')) {
$("#tblTestJSON").DataTable().clear();
}
var _tbl = $("#tblTestJSON").DataTable(_data);
_tbl.draw();
// $("#tblTestJSON").dataTable({
// "data": _data
// }).draw();
}
When I press the first button I get the results I expected. When I press the second button I get a tn/3 error and no data. I have tried to destroy the table and then I get the tn/4 error.
When I ave got this to display the different data then the pager hasn't redrawn.
Any help would be appreciated.
Scone
This discussion has been closed.
Answers
Why would you not just have to completely separate tables and just toggle the visibility on them?