Cannot make editor work

Cannot make editor work

sveatlosveatlo Posts: 9Questions: 3Answers: 0

Hi!
I'm trying to set up Editor to work with datatables for my second website, but unlike on the first page, it didn't work right away.
This is my current setup:

editor = new $.fn.dataTable.Editor({
    ajax: "<?=Uri::create('administrator/guests/manage_stays/'.$guest['id'])?>",
    table: "#guest_stays-data_table",
    fields: [
        {
            label: "ID",
            name: "id",
            type: "hidden"
        },
        {
            label: "Od:",
            name: "from_date",
            type: "date",
            def: function () { return new Date(); },
            dateFormat: 'dd.mm.yy'
        },
        {
            label: "Do:",
            name: "to_date",
            type: "date",
            def: function () { var tomorrow = new Date(); tomorrow.setDate(tomorrow.getDate() + 3); return tomorrow},
            dateFormat: 'dd.mm.yy'
        },
        {
            label: "Do magistrátovej knihy?:",
            name: "town_book",
            type: "text",
        },
        {
            label: "Kategória:",
            name: "town_book_category_id",
            type: "text",
        }
    ]
});

$('#order_spares-data_table').dataTable( {
    ajax: "<?=Uri::create('administrator/guests/stays/'.$guest['id'])?>",
    dom: "Tfrtip",
    columns: [
        {
            data: "id"
        },
        {
            data: "from_date"
        },
        {
            data: "to_date"
        },
        {
            data: "town_book"
        },
        {
            data: "town_book_category_id"
        }
    ],
    "tableTools": {
        sRowSelect: "os",
        aButtons: [
            { sExtends: "editor_create", editor: editor },
            { sExtends: "editor_edit",   editor: editor },
            { sExtends: "editor_remove", editor: editor }
        ]
    }
});

This is an example server response for table data: http://pastebin.com/Lg2xnmCR.
The loading works fine, as well as the DataTables plugin itself, but I cannot get the editing up and working. When trying to delete a row I get following error: Uncaught TypeError: Cannot read property 'id' of null. When trying to edit Uncaught TypeError: Cannot read property 'id' of undefined and when creating something, I get: Uncaught TypeError: Cannot read property 'oFeatures' of undefined after server (successfully) responds.
What could be wrong?

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin

    Unfortunately the PasteBin appears to have been removed, so I can't see what is being used there. Could you post it back up please? Also, can you show me the PHP code you are using?

    Thanks,
    Allan

  • sveatlosveatlo Posts: 9Questions: 3Answers: 0
  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin

    Thanks - I don't see your PHP code as well, but I would imagine that you have a field called id as well as the primary key also being id. I would suggest that you remove the field called id and just use the primary key (DT_RowId). Also remove the id from the Editor initialisation - you really don't want that to be editable :-)

    Allan

  • sveatlosveatlo Posts: 9Questions: 3Answers: 0

    removing the id key results in new error message: Uncaught TypeError: Cannot read property 'from_date' of undefined

  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin

    Are you able to link me to the page you are working on please? I don't immediately see what would be causing the problem.

    Thanks,
    Allan

  • sveatlosveatlo Posts: 9Questions: 3Answers: 0
    edited January 2015
  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin

    Thanks for the link. Could you try updating your DataTables to 1.10.4, the current release please. The page is currently using 1.10.2.

    Thanks,
    Allan

  • sveatlosveatlo Posts: 9Questions: 3Answers: 0

    Ok, I updated the DataTables, but still no change.

  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin
    Answer ✓

    Thanks for checking that - always a good starting place to have the latest software :-).

    It isn't working because of this line in your Editor initialisation:

    table: "#guest_stays-data_table",

    There is no such table on the page. I think you want #order_spares-data_table.

    Allan

This discussion has been closed.