Editor 'set' method undefined

Editor 'set' method undefined

djmm68djmm68 Posts: 20Questions: 7Answers: 0

Hello. I'm trying to programmatically register a record in the database when a button is clicked, using the set method, something like this:

editor.field( 'username' ).set( 'testuser' );
editor.field( 'discharge_date' ).set( myDate );                    

But when I click the button to run that code, I get the following error:

Uncaught TypeError: Cannot read properties of undefined (reading 'set')

I'm using DataTables Editor 1.6.1

Is there a problem with the set method for this version? I have used the get method, and it works correctly.


  • allanallan Posts: 62,083Questions: 1Answers: 10,179 Site admin

    I don't immediately recall an issue with that 1.6.1 that would cause that, but it was released in 2016, so maybe there was...

    1.6.2 included a bunch of fixes (although note specific to that it seems).

    A 1.x license includes up to 1.9.7, so I would recommend you upgrade to that. At the very least, you should upgrade to 1.6.5 which was the last in the 1.6.x series, but again, it is old and out of support now.


  • kthorngrenkthorngren Posts: 20,466Questions: 26Answers: 4,804

    I looked through the Release Notes for Editor versions 1.6.x but didn't see anything regarding this issue. I just tried Editor 1.6.1 and don't have a problem with your code snippet. My guess is the field name username or discharge_date is not correct. When I try 1.6.1 with an incorrect filed name I see the error you are getting.

    If you still need help please start by posting your Editor in Datatables init code.


  • djmm68djmm68 Posts: 20Questions: 7Answers: 0

    Allan, I agree that it's best to update to version 1.9.7; in fact, I have tried to create a test app, using the generator, and the 'set' method has worked perfectly in this version.
    Maybe I'll do it later, since I'm using several webapps whose migration would be a lot of work, considering that it includes Bootstrap4, Moment, Datetime, ckEditor, jqAlert... and some plugins of yours necessary for the above to work well on DataTables (published on datatables .net), so right now it would be too expensive in a matter of time, at least for me.

    Kevin, thanks for testing the snippet in version 1.6.1 so I can rule out a version issue; Also, I've checked the field names and they seem fine, but I'll spend a bit more digging into that, just in case.

    Actually, the 'set' method is only used in one of them. Therefore, before reading your answers, I had decided to implement a little trick:

    // Calculate row_id
    var penultimate_row = table.row( ':first', { order: 'applied' } ).data().DT_RowId.substr(4);
    var last_row = parseInt(penultimate) + 1;
    let row_id = "row_" + last_row.toString();
    // myDate is system date
    table.row.add( { "DT_RowId": row_id, "mytable": { "username": "testuser", "discharge_date": myDate }, "mytable_files": [] } ).draw();
    $.ajax({ url:'php/insert.php', method:'POST', data:{ username:"testuser", discharge_date:myDate  }, success:function(data) { alert("ok"); } });

    where "insert.php" is a server-side script to insert the record. Subsequently, the table must be refreshed.

    I know it's not the most orthodox way to do it, but so far it seems to work, it works for me as a temporary solution.

    Thank you both for your answers

Sign In or Register to comment.