Evaluate Datatables and Editor and been having a heck of a time. I generated a basic 'proof of concept' datatable with editor (PHP) to evaluate. And while initially appeared to work, I found out it does not save edit/updates.
Each time I click update I get:
An SQL error occurred: SQLSTATE[22P02]: Invalid text representation: 7 ERROR: invalid input syntax for integer: ""
Using Postgres database.
Primary key is "id" (lowercase). Though I am explicitly stating that in the editor.
Popup window Editor (not bubble or inline)
Code is as follows. This was generated using Generator. Since then, and as an attempt to figure it out, the only change I made was to add in isSrc and Field:inst('id'), which based on other readings shouldnt be needed since Iam using 'id' as the primary key.
(sorry, cant provide a link to an example)
PHP
<?php
/*
* Editor server script for DB table transaction
* Created by http://editor.datatables.net/generator
*/
// DataTables PHP library and database connection
include( "lib/DataTables.php" );
// Alias Editor classes so they are easy to use
use
DataTables\Editor,
DataTables\Editor\Field,
DataTables\Editor\Format,
DataTables\Editor\Mjoin,
DataTables\Editor\Options,
DataTables\Editor\Upload,
DataTables\Editor\Validate,
DataTables\Editor\ValidateOptions;
// Build our Editor instance and process the data coming from _POST
$out = Editor::inst( $db, 'transaction', 'id' )
->fields(
Field::inst( 'id' )->set(false),
Field::inst( 'transaction_date' )
->validator( Validate::dateFormat( 'Y-m-d' ) )
->getFormatter( Format::dateSqlToFormat( 'Y-m-d' ) )
->setFormatter( Format::dateFormatToSql( 'Y-m-d' ) ),
Field::inst( 'chq_num' ),
Field::inst( 'payee_orig' ),
Field::inst( 'payee' ),
Field::inst( 'memo_orig' ),
Field::inst( 'memo' ),
Field::inst( 'category_id' ),
Field::inst( 'tax_category_id' ),
Field::inst( 'transaction_amount' ),
Field::inst( 'balance' )
)
->process( $_POST )
->json();
JS
/*
* Editor client script for DB table transaction
* Created by http://editor.datatables.net/generator
*/
(function($){
$(document).ready(function() {
var editor = new $.fn.dataTable.Editor( {
ajax: 'php/table.transaction.php',
table: '#transaction',
idSrc: 'id',
fields: [
{
"label": "Date:",
"name": "transaction_date",
"type": "datetime",
"format": "YYYY-MM-DD"
},
{
"label": "Chq:",
"name": "chq_num"
},
{
"label": "Payee:",
"name": "payee_orig"
},
{
"label": "Memo:",
"name": "memo_orig"
},
{
"label": "Category:",
"name": "category_id"
},
{
"label": "Accounting:",
"name": "tax_category_id"
},
{
"label": "Amount:",
"name": "transaction_amount"
},
{
"label": "Balance:",
"name": "balance"
}
]
} );
} );
var table = $('#transaction').DataTable( {
dom: 'Bfrtip',
ajax: 'php/table.transaction.php',
columns: [
{
"data": "transaction_date"
},
{
"data": "chq_num"
},
{
"data": "payee_orig"
},
{
"data": "memo_orig"
},
{
"data": "category_id"
},
{
"data": "tax_category_id"
},
{
"data": "transaction_amount"
},
{
"data": "balance"
}
],
select: true,
lengthChange: false,
buttons: [
{ extend: 'create', editor: editor },
{ extend: 'edit', editor: editor },
{ extend: 'remove', editor: editor }
]
} );
} );
}(jQuery));