Hi,
I am using the Editor (1.2.3) with the PHP library for users to modify a table (admin_user) which has only one column (username) and that column is the primary key.
On update, I get a "Undefined offset: 0 in ...datatable/php/lib/Editor/Editor.php on line 544". Which is fair, it's a primary key, you wouldn't want to be able to do that usually... Also I want to here :D And the field actually get modified in the DB but the user sees the "an error has occured ..." message.
On delete, everything goes fine.
On create, I get a "offset: 0 in ...datatable/php/lib/Editor/Editor.php on line 507" (The row gets added in the DB and I get the "an error has occured ..." as well here). And it's my understanding that this should not happen and I have the feeling I am doing something wrong: I just can't figure out what, so here is my code!!
The JS and HTML:
And the PHP:
Any help/pointer/suggestion would be appreciated!
Thanks
I am using the Editor (1.2.3) with the PHP library for users to modify a table (admin_user) which has only one column (username) and that column is the primary key.
On update, I get a "Undefined offset: 0 in ...datatable/php/lib/Editor/Editor.php on line 544". Which is fair, it's a primary key, you wouldn't want to be able to do that usually... Also I want to here :D And the field actually get modified in the DB but the user sees the "an error has occured ..." message.
On delete, everything goes fine.
On create, I get a "offset: 0 in ...datatable/php/lib/Editor/Editor.php on line 507" (The row gets added in the DB and I get the "an error has occured ..." as well here). And it's my understanding that this should not happen and I have the feeling I am doing something wrong: I just can't figure out what, so here is my code!!
The JS and HTML:
var editor; $(document).ready(function() { editor = new $.fn.dataTable.Editor( { "ajaxUrl": "assets/datatable/php/ajax_adminusers.php", "domTable": "#example", "fields": [ { "label": "User Name (NT ID):", "name": "username" } ] } ); // New record $('#btn_editor_create').click(function (e) { e.preventDefault(); editor.create( 'Create new record', { "label": "Add", "fn": function () { editor.submit() } } ); } ); // Edit record $('#example').on('click', 'a.editor_edit', function (e) { e.preventDefault(); editor.edit( $(this).parents('tr')[0], 'Edit record', { "label": "Update", "fn": function () { editor.submit() } } ); } ); // Delete a record (asking a user for confirmation) $('#example').on('click', 'a.editor_remove', function (e) { e.preventDefault(); editor.message( "Are you sure you want to remove this row?" ); editor.remove( $(this).parents('tr')[0], 'Delete row', { "label": "Confirm", "fn": function () { this.submit(); } }); }); $('#example').dataTable( { "sDom": "lfrtip", "iDisplayLength": 50, "sAjaxSource": "assets/datatable/php/ajax_adminusers.php", "aoColumns": [ { "mData": "username" }, { "mData": null, "sClass": "center", "sDefaultContent": '<a href="" class="editor_edit">Edit</a> / <a href="" class="editor_remove">Delete</a>' } ] }); } ); </script> <div class="container"> <div class="row"> <button type="button" id="btn_editor_create" class="btn btn-primary">Create New Record</button> <br> <br> <table style="width:100% !important; cellpadding:0; cellspacing:0; border:0;" class="table table-striped table-condensed" id="example"> <thead> <tr> <th>Username</th> <th>Admin</th> </tr> </thead> </table> </div>
And the PHP:
include( "lib/DataTables.php" ); use DataTables\Editor, DataTables\Editor\Field, DataTables\Editor\Format, DataTables\Editor\Join, DataTables\Editor\Validate; Editor::inst( $db, 'admin_user', 'username' ) ->fields( Field::inst( 'username' )->validator( 'Validate::required' ) ) ->process( $_POST ) ->json();
Any help/pointer/suggestion would be appreciated!
Thanks