myTable.row is not a function when using row().edit

myTable.row is not a function when using row().edit

alohasalohas Posts: 7Questions: 3Answers: 0
edited August 2022 in Free community support

Hi,

I am keep getting error - "myTable.row is not a function" and I have no clue how to fix it.

I tried to use both DataTable and dataTable, not helping.

$(document).ready( function () {
  
    var currentUser = _spPageContextInfo.userId;
    generateTable(currentUser);

});


function generateTable(currentUser){
    var JsonObject;
    var employees = [];

    $('#table_id').DataTable({
        dom: 'frtBip',
        select: "multi",
        ajax: {
            url: "RestAPI call"
            type: "GET",
            headers:
        {

            "Accept": "application/json;odata=verbose"
        },
            dataSrc: function (data) {
                var dataresults = data.d.results;
                
                for (var i = 0; i < dataresults.length; i++) {
                    // console.log(dataresults[i])['Title'];
                    //testArray.push(dataresults[i]['Title']);
                    console.log(dataresults[i]);

                    employees.push({firstName:dataresults[i]['FirstName'],lastName:dataresults[i]['LastName'],position:dataresults[i]['Position'],salary:dataresults[i]['Salary']})
                    
                }
                JsonObject = JSON.parse(JSON.stringify(employees));
                // console.log(JsonObject);


                return JsonObject;

            },
            dataType: "JSON",

            error: function (xhr, status, error) {
                console.log("Failed");
            },
            

        },
        columnDefs: [{
            "defaultContent": "-",
            "targets": "_all"
        },
    ],
    columns: [
        {data: 'firstName'},
        {data: 'lastName'},
        {data: 'position'},
        {data: 'salary'}
    ],
        buttons: [{
            text: 'Yes',
            action: function (){
                console.log('test');
            }
        }]

    });


    var myTable = $('#table_id').DataTable();
 
    $('#table_id').on( 'click', 'tbody tr', function () {
        myTable.row( this ).edit();
    } );
}

Edited by Allan - Syntax highlighting. Details on how to highlight code using markdown can be found in this guide.

Answers

  • rf1234rf1234 Posts: 2,801Questions: 85Answers: 406

    You need Editor for this but I don't see your Editor initialization.

    I always edit existing rows using the select extension by the way. That makes it a lot easier - but of course this also requires Editor.

  • kthorngrenkthorngren Posts: 20,144Questions: 26Answers: 4,736
    edited August 2022

    I would move line 59 (var myTable = $('#table_id').DataTable();) inside your click event.

    Kevin

  • alohasalohas Posts: 7Questions: 3Answers: 0

    @rf1234 I tried to use Editor initialization but I get the error - "$.fn.DataTable.Editor is not a constructor"
    Do I need to purchase a license in order to use Editor?

  • kthorngrenkthorngren Posts: 20,144Questions: 26Answers: 4,736

    Do I need to purchase a license in order to use Editor?

    You can download a trial version but after the trial is over you need to purchase a license. You actually need to Download Editor to use in a trial and to run the licensed version. I think you get the above error if you try loading Editor via CDN.

    Kevin

  • allanallan Posts: 61,446Questions: 1Answers: 10,054 Site admin

    myTable.row is not a function

    With the code:

        $('#table_id').on( 'click', 'tbody tr', function () {
            var myTable = $('#table_id').DataTable();
            myTable.row( this ).edit();
        } );
    

    And Editor not loaded I would expect the error to be that edit is not a function. By your subject title says that row is not a function. It certainly should be there.

    Could you confirm for us please?

    Allan

Sign In or Register to comment.