User administration example, how to deal with password fields
User administration example, how to deal with password fields
Using Editor, I'm pulling a few "user related" fields from a table in which the password is encrypted on the PHP site before being entered into the database.
When Editor table is initialized, the password field is pulled and populated with the hashed password. This is an awkward behavior. Ideally, I'd like to NOT pull that field when drawing (reading from the database) the table, but still allow the field to up updated with inline (or standard) editing.
Any idea how that would be accomplished?
users_editor = new $.fn.dataTable.Editor( {
ajax: "/users/api/",
table: "#tblUsers",
fields: [
{
label: "Firstname",
name: "firstname"
}, {
label: "Last Name",
name: "lastname"
}, {
label: "Username",
name: "username"
}, {
label: "Password",
name: "password",
type: "password"
}
]
} );
// Activate an inline edit on click of a table cell
$('#tblUsers').on( 'click', 'tbody td:not(:first-child)', function (e) {
users_editor.inline( this );
} );
$('#tblUsers').DataTable( {
dom: "Tfrtip",
ajax: "/users/api/",
columns: [
{ data: null, defaultContent: '', orderable: false },
{ data: "firstname" },
{ data: "lastname" },
{ data: "username" },
{ data: "password" }
],
order: [ 1, 'desc' ],
lengthMenu: [20, 50],
"bAutoWidth": false,
tableTools: {
sRowSelect: "os",
sRowSelector: 'td:first-child',
aButtons: [
{ sExtends: "editor_create", editor: users_editor },
{ sExtends: "editor_edit", editor: users_editor },
{ sExtends: "editor_remove", editor: users_editor }
]
}
} );
This question has an accepted answers - jump to answer
Answers
I was able to solve this by using a custom getFormatter:
Format.php:
You should also be able to use the
get()
method for the field and set it tofalse
.But your method is a nice way of doing it as well!
Allan