Cant Access DataTable when I click an element in a td
Cant Access DataTable when I click an element in a td
dt8485
Posts: 7Questions: 0Answers: 0
I am trying to click an td which opens my dialog box.
Its working for this column
" $("#usersTable tbody td:contains(\"View Details\")").live('click', function () {"
But instead of that column, I have 3 anchor links when I click on the First one with class=view, it should work the same for "sTitle": "Action"
column.
In the rest of the clicks function , when I am accessing through class name. I am not able to get the oData which I am getting in First live function.
Can you let me know where the problem is:
Thanks
var dataTable;
//var anOpen = [];
$(document).ready(function () {
$("#GetUserBtn").click(function (e) {
e.preventDefault();
var postUrl = $("#UserInfo").attr("action");
var roleCode = $("#RoleCode").val();
if (roleCode.length <= 0) {
$(".roleValidation").show();
return false;
}
else {
$(".roleValidation").hide();
$.post(postUrl, { "roleCode": roleCode }, function (data) {
var userData = data.Data != null ? data.Data : [];
dataTable = $('#usersTable').dataTable({
"bJQueryUI": true,
"aaData": userData,
"oLanguage": {
"sZeroRecords": "No Records Found"
},
"bDestroy": true,
"aoColumns": [
{ "sTitle": "Full Name", "mDataProp": "FullName" },
{ "sTitle": "UserName", "mDataProp": "UserName" },
{ "sTitle": "Email", "mDataProp": "Email" },
{ "sTitle": "Role", "mDataProp": "RoleName" },
{ "sTitle": "Action", "sClass": "control center", "mDataProp": null, "sDefaultContent":
'View Details'
},
{ "sClass": "control center", "mDataProp": null, "sDefaultContent":
'' +
'' +
''
}]
});
});
return false;
}
});
$("#usersTable tbody td:contains(\"View Details\")").live('click', function () {
var oTable = $('#usersTable').dataTable();
var nTr = this.parentNode;
var oData = oTable.fnGetData(nTr);
$('#dialogcontent').dialog({
title: "Details",
autoOpen: false,
width: 600
});
document.getElementById('dialogcontent').innerHTML = 'Full Name:' + oData.FullName + '' +
'UserName:' + oData.UserName + '' +
'Email:' + oData.Email + '' +
'Company Id:' + oData.CompanyId + '' +
'Role:' + oData.RoleName + '' +
'Divisional List:' + oData.DivList + '' +
'Regional List:' + oData.RegList + '' +
'Facility List:' + oData.FacList + '' +
'DirectAccessUrl:' + oData.DirectAccessUrl + '' +
'DeleteOnLogout:' + oData.DeleteOnLogout + '' +
'';
$('#dialogcontent').dialog('open');
});
$(".view").live('click', function () {
var oTable = $('#usersTable').dataTable();
var nTr = this.parentNode;
var oData = oTable.fnGetData(nTr);
$('#dialogcontent').dialog({
title: "Details",
autoOpen: false,
width: 600
});
document.getElementById('dialogcontent').innerHTML = 'Full Name:' + oData.FullName + '' +
'UserName:' + oData.UserName + '' +
'Email:' + oData.Email + '' +
'Company Id:' + oData.CompanyId + '' +
'Role:' + oData.RoleName + '' +
'Divisional List:' + oData.DivList + '' +
'Regional List:' + oData.RegList + '' +
'Facility List:' + oData.FacList + '' +
'DirectAccessUrl:' + oData.DirectAccessUrl + '' +
'DeleteOnLogout:' + oData.DeleteOnLogout + '' +
'';
$('#dialogcontent').dialog('open');
});
$(".update").live('click', function () {
var oTable = $('#usersTable').dataTable();
var nTr = this.parentNode;
var oData = oTable.fnGetData(nTr);
var username = oData.UserName;
window.location.href = '/UpdateUser/Update/Username=' + username;
});
$(".change").live('click', function () {
var oTable = $('#usersTable').dataTable();
var nTr = this.parentNode;
var oData = oTable.fnGetData(nTr);
var username = oData.UserName;
window.location.href = '/ChangePwd/Change/Username=' + username;
});
});
Its working for this column
" $("#usersTable tbody td:contains(\"View Details\")").live('click', function () {"
But instead of that column, I have 3 anchor links when I click on the First one with class=view, it should work the same for "sTitle": "Action"
column.
In the rest of the clicks function , when I am accessing through class name. I am not able to get the oData which I am getting in First live function.
Can you let me know where the problem is:
Thanks
var dataTable;
//var anOpen = [];
$(document).ready(function () {
$("#GetUserBtn").click(function (e) {
e.preventDefault();
var postUrl = $("#UserInfo").attr("action");
var roleCode = $("#RoleCode").val();
if (roleCode.length <= 0) {
$(".roleValidation").show();
return false;
}
else {
$(".roleValidation").hide();
$.post(postUrl, { "roleCode": roleCode }, function (data) {
var userData = data.Data != null ? data.Data : [];
dataTable = $('#usersTable').dataTable({
"bJQueryUI": true,
"aaData": userData,
"oLanguage": {
"sZeroRecords": "No Records Found"
},
"bDestroy": true,
"aoColumns": [
{ "sTitle": "Full Name", "mDataProp": "FullName" },
{ "sTitle": "UserName", "mDataProp": "UserName" },
{ "sTitle": "Email", "mDataProp": "Email" },
{ "sTitle": "Role", "mDataProp": "RoleName" },
{ "sTitle": "Action", "sClass": "control center", "mDataProp": null, "sDefaultContent":
'View Details'
},
{ "sClass": "control center", "mDataProp": null, "sDefaultContent":
'' +
'' +
''
}]
});
});
return false;
}
});
$("#usersTable tbody td:contains(\"View Details\")").live('click', function () {
var oTable = $('#usersTable').dataTable();
var nTr = this.parentNode;
var oData = oTable.fnGetData(nTr);
$('#dialogcontent').dialog({
title: "Details",
autoOpen: false,
width: 600
});
document.getElementById('dialogcontent').innerHTML = 'Full Name:' + oData.FullName + '' +
'UserName:' + oData.UserName + '' +
'Email:' + oData.Email + '' +
'Company Id:' + oData.CompanyId + '' +
'Role:' + oData.RoleName + '' +
'Divisional List:' + oData.DivList + '' +
'Regional List:' + oData.RegList + '' +
'Facility List:' + oData.FacList + '' +
'DirectAccessUrl:' + oData.DirectAccessUrl + '' +
'DeleteOnLogout:' + oData.DeleteOnLogout + '' +
'';
$('#dialogcontent').dialog('open');
});
$(".view").live('click', function () {
var oTable = $('#usersTable').dataTable();
var nTr = this.parentNode;
var oData = oTable.fnGetData(nTr);
$('#dialogcontent').dialog({
title: "Details",
autoOpen: false,
width: 600
});
document.getElementById('dialogcontent').innerHTML = 'Full Name:' + oData.FullName + '' +
'UserName:' + oData.UserName + '' +
'Email:' + oData.Email + '' +
'Company Id:' + oData.CompanyId + '' +
'Role:' + oData.RoleName + '' +
'Divisional List:' + oData.DivList + '' +
'Regional List:' + oData.RegList + '' +
'Facility List:' + oData.FacList + '' +
'DirectAccessUrl:' + oData.DirectAccessUrl + '' +
'DeleteOnLogout:' + oData.DeleteOnLogout + '' +
'';
$('#dialogcontent').dialog('open');
});
$(".update").live('click', function () {
var oTable = $('#usersTable').dataTable();
var nTr = this.parentNode;
var oData = oTable.fnGetData(nTr);
var username = oData.UserName;
window.location.href = '/UpdateUser/Update/Username=' + username;
});
$(".change").live('click', function () {
var oTable = $('#usersTable').dataTable();
var nTr = this.parentNode;
var oData = oTable.fnGetData(nTr);
var username = oData.UserName;
window.location.href = '/ChangePwd/Change/Username=' + username;
});
});
This discussion has been closed.