Editor Update Issue

Editor Update Issue

andyhclarkandyhclark Posts: 3Questions: 0Answers: 0
edited May 2013 in Editor
Hi DataTables Team

Just started using my 15 day trial of the editor, fantastic piece of work guys - but ...... I can insert and delete fine but on update I get the following message:

[quote]Notice: Undefined offset: 0 in /var/www/hub.citygate.co.uk/wp-includes/DataTablesEditor/php/lib/Editor/Editor.php on line 544
{"id":"row_","error":"","fieldErrors":[],"data":[],"row":null}[/quote]

Everything's OK using the generator, only difference here is that I'm using an existng dataTable and adding the editor:

[code]
var $j = jQuery.noConflict();
$j(document).ready(function() {
// $j('#tHdr').css('background-color','#dddddd');

editor = new $j.fn.dataTable.Editor( {
"ajaxUrl": "/wp-includes/DataTablesEditor/php/table.hub_nps.php",
"domTable": "#tGrid",
"idSrc": "id",
"fields": [
{
"label": "id",
"name": "id",
"type": "readonly"
}, {
"label": "Date:",
"name": "date_visit",
"type": "date",
"dateFormat": "dd/mm/y",
"dateImage": "images\/calender.png"
}, {
"label": "Employee:",
"name": "employee"
}, {
"label": "Score:",
"name": "score"
}, {
"label": "Comments:",
"name": "comments",
"type": "textarea"
}
]
} );



$j('#tGrid').dataTable( {
"sDom": "Tfrtip",
"iDisplayLength": 100,
"aaSorting": [[2,'desc'], [1,'asc']],
"aoColumns": [
{ "bVisible" :true, "mData": "id", "aTargets":[0] },
{ "sWidth" : "10%", "mData": "date_visit", "aTargets":[1] },
{ "sWidth" : "20%", "mData": "employee", "aTargets":[2] },
{ "sWidth" : "8%", "mData": "score", "aTargets":[3] },
{ "bSortable": false, "mData": "comments","sWidth" : "62%", "aTargets":[4] }],
"oTableTools": {
"sRowSelect": "single",
"aButtons": [
{ "sExtends": "editor_create", "editor": editor },
{ "sExtends": "editor_edit", "editor": editor },
{ "sExtends": "editor_remove", "editor": editor }
]
}
});

[/code]

And here's the PHP:

[code]
<?php

/*
* Editor server script for DB table hub_nps
* Automatically generated by http://editor.datatables.net/generator
*/

// DataTables PHP library
include( "lib/DataTables.php" );

// Alias Editor classes so they are easy to use
use
DataTables\Editor,
DataTables\Editor\Field,
DataTables\Editor\Format,
DataTables\Editor\Join,
DataTables\Editor\Validate;


// Build our Editor instance and process the data coming from _POST
Editor::inst( $db, 'hub_nps' )
->fields(
Field::inst( 'id' ),
Field::inst( 'date_visit' )
->validator( 'Validate::dateFormat_required', 'd/m/y' )
->getFormatter( 'Format::date_sql_to_format', 'd/m/y' )
->setFormatter( 'Format::date_format_to_sql', 'd/m/y' ),
Field::inst( 'employee' )
->validator( 'Validate::maxLen_required', 100 ),
Field::inst( 'score' )
->validator( 'Validate::required' ),
Field::inst( 'comments' )
->validator( 'Validate::required' )
)
->process( $_POST )
->json();

[/code]

Here's a link to the page (I'd removed the date field in case it was something to do with dd/mm/yyyyy formatting):

http://hub.citygate.co.uk/?page_id=126

Any ideas? It looks like the row number is not getting passed.

Many thanks

Andy

Replies

  • andyhclarkandyhclark Posts: 3Questions: 0Answers: 0
    Got it sorted - what I wasn't doing was providing the row id in the element. Works a treat now.

    I shall definitely be ordering at the expiry of the trial.
  • allanallan Posts: 63,512Questions: 1Answers: 10,472 Site admin
    Hi Andy,

    Sorry I didn't get a chance to reply before you sorted it out yourself! Good to hear that you've got it working now. I'll look at adding an error condition into the libraries for this state, as the primary key is quite important for the operation of Editor as you have seen!

    Thanks for the feedback!

    Regards,
    Allan
This discussion has been closed.