Keep fnCreatedCell format after fnUpdate
Keep fnCreatedCell format after fnUpdate
Razorphyn
Posts: 5Questions: 0Answers: 0
Hi,
I have this function inside every column of the table:
[code],fnCreatedCell: function (nTd, sData, oData, iRow, iCol) {$(nTd).html("Department" + $(nTd).html() + '');}[/code]
and when I create the table everything is fine, but when I update a row the fnCreatedCell changes doesn't apply, basically the table ignore it's existence, if it is a normal behaviour is there a way to keep the fnCreatedCell format? Because I have noticed that sometimes the some cells of the same row keep the format, otherwise I will attach the structure to the update object
This my site:
http://razorphyn.com/products/support/user/users.php
Login details: admin@admin.com - Admin
Next go to "users" or "tickets->tickets list" or "administrator->Departments Managment" or "Administrator->FAQs Managment" or every page that require a table.
This is an example(it's pretty unredable):
Create the table:
[code]
var table;
var request = $.ajax({
type: "POST",
url: "../php/admin_function.php",
data: {act: "retrive_users"},
dataType: "json",
success: function (a) {
if ("ret" == a.response || "empty" == a.response) {
var b = a.information.length;
for (i = 0; i < b; i++)
a.information[i].action = '';
$(".loading:first").remove();
table = $("#usertable").dataTable({
sDom: "<<'span6'l><'span6'f>r>t<<'span6'i><'span6'p>>",
sWrapper: "dataTables_wrapper form-inline",
bProcessing: !0,
aaData: a.information,
oLanguage: {sEmptyTable: "No Users"},
aoColumns: [{
sTitle: "Number",
mDataProp: "num",
sWidth: "60px",
sClass: "visible-desktop",
fnCreatedCell: function (nTd, sData, oData, iRow, iCol) {
$(nTd).html("Number: " + $(nTd).html() + '');
}
}, {
sTitle: "Name",
mDataProp: "name",
fnCreatedCell: function (nTd, sData, oData, iRow, iCol) {
$(nTd).html("Name: " + $(nTd).html() + '');
}
}, {
sTitle: "Mail",
mDataProp: "mail",
fnCreatedCell: function (nTd, sData, oData, iRow, iCol) {
$(nTd).html("Mail: " + $(nTd).html() + '');
}
}, {
sTitle: "Status/Role",
mDataProp: "status",
fnCreatedCell: function (nTd, sData, oData, iRow, iCol) {
$(nTd).html("Status/Role: " + $(nTd).html() + '');
}
}, {
sTitle: "Holiday",
mDataProp: "holiday",
sWidth: "60px",
sClass: "hidden-phone",
fnCreatedCell: function (nTd, sData, oData, iRow, iCol) {
$(nTd).html("Holiday: " + $(nTd).html() + '');
}
}, {
sTitle: "Rating",
mDataProp: "rating",
sWidth: "60px",
sClass: "hidden-phone",
fnCreatedCell: function (nTd, sData, oData, iRow, iCol) {
$(nTd).html("Rating: " + $(nTd).html() + '');
}
}, {
sTitle: "Tooggle",
mDataProp: "action",
bSortable: !1,
bSearchable: !1,
sWidth: "60px",
fnCreatedCell: function (nTd, sData, oData, iRow, iCol) {
$(nTd).html("Toogle: " + $(nTd).html() + '');
}
}]
})
}
else
noty({text: a[0],type: "error",timeout: 9E3})
}
});
request.fail(function (a, b) {noty({text: "Ajax Error: " + b,type: "error",timeout: 9E3})});
[/code]
Update the information:
[code]
$(document).on("click", ".submit_changes", function () {
var a = $(this).parent();
a.children("input").each(function () {
$(this).attr("disabled", "disabled")
});
a.children("select").each(function () {
$(this).attr("disabled", "disabled")
});
var b = a.children('input[name="usr_edit_id"]').val(),
k = parseInt(a.children('input[name="usr_edit_pos"]').val()),
e = a.find('input[name="usr_edit_name"]').val().replace(/\s+/g, " "),
f = a.find('input[name="usr_edit_mail"]').val().replace(/\s+/g, " "),
g = a.find('select[name="usr_role"]').val(),
c = a.find('select[name="usr_holiday"]').val(),
l = a.find('input[name="usr_rate"]').val(),
h = [];
"1" == g && a.find('input[name="ass_usr_depa"]:checked').each(function () {
h.push($(this).val())
});
"" != e.replace(/\s+/g, "") && "" != f.replace(/\s+/g, "") ? ($.ajax({
type: "POST",
url: "../php/admin_function.php",
data: {
act: "update_user_info",
id: b,
name: e,
mail: f,
status: g,
holiday: c,
seldepa: h
},
dataType: "json",
success: function (d) {
"Updated" == d[0] ? (
d = '',
c = 1 == c ? "Yes" : "No",
info = {
num: b,
name: e,
mail: f,
status: a.find('select[name="usr_role"] option:selected').text(),
holiday: c,
rating: l,
action: d
}, table.fnUpdate(info, k), a.prev().remove(), a.remove()
) : (a.children("input").each(function () {
$(this).removeAttr("disabled", "disabled")
}), a.children("select").each(function () {
$(this).removeAttr("disabled", "disabled")
}), noty({text: d[0],type: "error",timeout: 9E3}))
}
}).fail(function (a, b) {noty({text: b,type: "error",timeout: 9E3})
})) : noty({text: data[0],type: "Empty Field",timeout: 9E3});
return !1
});
[/code]
Thanks
I have this function inside every column of the table:
[code],fnCreatedCell: function (nTd, sData, oData, iRow, iCol) {$(nTd).html("Department" + $(nTd).html() + '');}[/code]
and when I create the table everything is fine, but when I update a row the fnCreatedCell changes doesn't apply, basically the table ignore it's existence, if it is a normal behaviour is there a way to keep the fnCreatedCell format? Because I have noticed that sometimes the some cells of the same row keep the format, otherwise I will attach the structure to the update object
This my site:
http://razorphyn.com/products/support/user/users.php
Login details: admin@admin.com - Admin
Next go to "users" or "tickets->tickets list" or "administrator->Departments Managment" or "Administrator->FAQs Managment" or every page that require a table.
This is an example(it's pretty unredable):
Create the table:
[code]
var table;
var request = $.ajax({
type: "POST",
url: "../php/admin_function.php",
data: {act: "retrive_users"},
dataType: "json",
success: function (a) {
if ("ret" == a.response || "empty" == a.response) {
var b = a.information.length;
for (i = 0; i < b; i++)
a.information[i].action = '';
$(".loading:first").remove();
table = $("#usertable").dataTable({
sDom: "<<'span6'l><'span6'f>r>t<<'span6'i><'span6'p>>",
sWrapper: "dataTables_wrapper form-inline",
bProcessing: !0,
aaData: a.information,
oLanguage: {sEmptyTable: "No Users"},
aoColumns: [{
sTitle: "Number",
mDataProp: "num",
sWidth: "60px",
sClass: "visible-desktop",
fnCreatedCell: function (nTd, sData, oData, iRow, iCol) {
$(nTd).html("Number: " + $(nTd).html() + '');
}
}, {
sTitle: "Name",
mDataProp: "name",
fnCreatedCell: function (nTd, sData, oData, iRow, iCol) {
$(nTd).html("Name: " + $(nTd).html() + '');
}
}, {
sTitle: "Mail",
mDataProp: "mail",
fnCreatedCell: function (nTd, sData, oData, iRow, iCol) {
$(nTd).html("Mail: " + $(nTd).html() + '');
}
}, {
sTitle: "Status/Role",
mDataProp: "status",
fnCreatedCell: function (nTd, sData, oData, iRow, iCol) {
$(nTd).html("Status/Role: " + $(nTd).html() + '');
}
}, {
sTitle: "Holiday",
mDataProp: "holiday",
sWidth: "60px",
sClass: "hidden-phone",
fnCreatedCell: function (nTd, sData, oData, iRow, iCol) {
$(nTd).html("Holiday: " + $(nTd).html() + '');
}
}, {
sTitle: "Rating",
mDataProp: "rating",
sWidth: "60px",
sClass: "hidden-phone",
fnCreatedCell: function (nTd, sData, oData, iRow, iCol) {
$(nTd).html("Rating: " + $(nTd).html() + '');
}
}, {
sTitle: "Tooggle",
mDataProp: "action",
bSortable: !1,
bSearchable: !1,
sWidth: "60px",
fnCreatedCell: function (nTd, sData, oData, iRow, iCol) {
$(nTd).html("Toogle: " + $(nTd).html() + '');
}
}]
})
}
else
noty({text: a[0],type: "error",timeout: 9E3})
}
});
request.fail(function (a, b) {noty({text: "Ajax Error: " + b,type: "error",timeout: 9E3})});
[/code]
Update the information:
[code]
$(document).on("click", ".submit_changes", function () {
var a = $(this).parent();
a.children("input").each(function () {
$(this).attr("disabled", "disabled")
});
a.children("select").each(function () {
$(this).attr("disabled", "disabled")
});
var b = a.children('input[name="usr_edit_id"]').val(),
k = parseInt(a.children('input[name="usr_edit_pos"]').val()),
e = a.find('input[name="usr_edit_name"]').val().replace(/\s+/g, " "),
f = a.find('input[name="usr_edit_mail"]').val().replace(/\s+/g, " "),
g = a.find('select[name="usr_role"]').val(),
c = a.find('select[name="usr_holiday"]').val(),
l = a.find('input[name="usr_rate"]').val(),
h = [];
"1" == g && a.find('input[name="ass_usr_depa"]:checked').each(function () {
h.push($(this).val())
});
"" != e.replace(/\s+/g, "") && "" != f.replace(/\s+/g, "") ? ($.ajax({
type: "POST",
url: "../php/admin_function.php",
data: {
act: "update_user_info",
id: b,
name: e,
mail: f,
status: g,
holiday: c,
seldepa: h
},
dataType: "json",
success: function (d) {
"Updated" == d[0] ? (
d = '',
c = 1 == c ? "Yes" : "No",
info = {
num: b,
name: e,
mail: f,
status: a.find('select[name="usr_role"] option:selected').text(),
holiday: c,
rating: l,
action: d
}, table.fnUpdate(info, k), a.prev().remove(), a.remove()
) : (a.children("input").each(function () {
$(this).removeAttr("disabled", "disabled")
}), a.children("select").each(function () {
$(this).removeAttr("disabled", "disabled")
}), noty({text: d[0],type: "error",timeout: 9E3}))
}
}).fail(function (a, b) {noty({text: b,type: "error",timeout: 9E3})
})) : noty({text: data[0],type: "Empty Field",timeout: 9E3});
return !1
});
[/code]
Thanks
This discussion has been closed.
Replies
Allan