New to Editor (15-day trial period) - "Edit" function does not trigger

New to Editor (15-day trial period) - "Edit" function does not trigger

ecostello13ecostello13 Posts: 2Questions: 0Answers: 0
edited August 2012 in Editor
Hi - I have a table created from a Javascript array. It displays and scrolls fine. When selecting a row for editing, it highlights correctly. However, when clicking the "Update" (Edit) button, nothing happens. I'm sure there's a configuration problem in the editor constructor or some other newbie error, but I don't see it. I've poured through the docs and the datatables.net forums with no luck. Could it be caused because I have not set up the server side PHP code yet? I'd expect the editing part to happen and then fail when it tried to submit the changes in this case. I'd be grateful if someone could point out where I got sideways.

Full beta site is here: http://www.million-monkeys.com/tvcyo
(Note - the password 'edittest' will expand the table to see all editable columns)

Editor constructor and DataTables configuration snippets below (commented code lines are different things I've played with over time):
[code]
var buildGameEditor = function()
{
return
(
new $.fn.dataTable.Editor( {
"ajaxUrl": "php/table.games.php", // NOTE: This file does not exist
"domTable" : "#gamesTable",
"dbTable" : "games",
"fields": [
{
"label": "ID",
"name": "game_id",
"type": "text"
},
{
"label": "Date",
"name": "game_date",
"type": "date",
"dateFormat": "yy-mm-dd",
"dateImage": "./js/images/calender.png"
},
{
"label": "Time",
"name": "game_time",
"type": "text"
},
{
"label": "Court",
"name": "game_gym_name",
"type": "text"
},
{
"label": "Team 1",
"name": "game_full_team1_name",
"type": "text"
},
{
"label": "Score 1",
"name": "game_team1_score",
"type": "text"
},
{
"label": "SR 1",
"name": "game_team1_sportsrating",
"type": "text"
},
{
"label": "Team 2",
"name": "game_full_team2_name",
"type": "text"
},
{
"label": "Score 2",
"name": "game_team1_score",
"type": "text"
},
{
"label": "SR 2",
"name": "game_team2_sportsrating",
"type": "text"
},
{
"label": "Comment",
"name": "game_comment",
"type": "textarea"
}
]
} )
);
}


var createGamesTable1 = function( )
{
var gameCount = 0;
var tempRow = "";
var gTable = [];
var gameIndex = 0;
var team1;
var team2;
var useThisGame = false;
var gameEditor;

writeLog( "createGamesTable1()" );
$('#divGamesTable').hide();
$('#divGamesTable').html("");

gameEditor = buildGameEditor();

for (var i=0; i

Replies

  • allanallan Posts: 51,411Questions: 1Answers: 7,752 Site admin
    Hi,

    You've hit a quirk of Javascript here...

    [code]
    var buildGameEditor = function()
    {
    return
    (
    ...
    [/code]

    Your `buildGameEditor` function is always going to return `undefined` (you can check by looking at the variable in the console). The reason for this is that return is white space sensitive - or more correctly - the Automatic Semi-colon Insertion (ASI) of Javascript, The JS engine thinks you've make an error there, and so runs:

    [code]
    var buildGameEditor = function()
    {
    return;
    }
    [/code]

    i.e. an undefined return. This is one of the reason why, imho, putting semi-colons in Javascript is very important :-)

    The end result is that you get a Javascript error at the moment, as `gameEditor` is `undefined`, rather than the Editor instance:

    > TypeError: 'null' is not an object (evaluating 'c.editor.edit')

    Just move your bracket onto the return line and it should work nicely :-)

    [code]
    var buildGameEditor = function()
    {
    return (
    ...
    [/code]

    Allan
  • ecostello13ecostello13 Posts: 2Questions: 0Answers: 0
    Allan - you da man! I owe you a beer!

    I saw the gameEditor instance undefined, but figured it was an artifact of misconfiguration in the constructor. I would have been a long time figuring this out.

    PS - is there a way to tell Javascript not to be so smart? :-)

    Cheers!
  • allanallan Posts: 51,411Questions: 1Answers: 7,752 Site admin
    Heh - no problem at all. Let me know how you get on with Editor!

    > PS - is there a way to tell Javascript not to be so smart? :-)

    CoffeeScript perhaps? ;-)

    Allan
This discussion has been closed.