Datatable inline edit error- Cannot read property 'replace' of undefined

Datatable inline edit error- Cannot read property 'replace' of undefined

bikram.b@bitordertech.combikram.b@bitordertech.com Posts: 7Questions: 2Answers: 0

Hi All,
I am getting this error 'Cannot read property 'replace' of undefined', when I try to edit a cell and change the content and hit 'enter'.I am following this basic example.https://editor.datatables.net/examples/inline-editing/simple

Answers

  • allanallan Posts: 63,252Questions: 1Answers: 10,420 Site admin

    Can you give me a link to your page showing the issue so I can try to debug the problem please? I assume that the link you give works okay for you, so we would need to identify the difference between the two pages.

    Thanks,
    Allan

  • bikram.b@bitordertech.combikram.b@bitordertech.com Posts: 7Questions: 2Answers: 0
    edited June 2016

    Here is the code. please check.
    html-

    <table id="example" class="display" cellspacing="0" width="100%">
            <thead>
                <tr>
                    <th>Name</th>
                    <th>Position</th>
                    <th>Office</th>
                    <th>Age</th>
                    <th>Start date</th>
                    <th>Salary</th>
                </tr>
            </thead>
            <tfoot>
                <tr>
                    <th>Name</th>
                    <th>Position</th>
                    <th>Office</th>
                    <th>Age</th>
                    <th>Start date</th>
                    <th>Salary</th>
                </tr>
            </tfoot>
            <tbody>
                <tr>
                    <td>Tiger Nixon</td>
                    <td>System Architect</td>
                    <td>Edinburgh</td>
                    <td>61</td>
                    <td>2011/04/25</td>
                    <td>$320,800</td>
                </tr>
                <tr>
                    <td>Garrett Winters</td>
                    <td>Accountant</td>
                    <td>Tokyo</td>
                    <td>63</td>
                    <td>2011/07/25</td>
                    <td>$170,750</td>
                </tr>
                <tr>
                    <td>Ashton Cox</td>
                    <td>Junior Technical Author</td>
                    <td>San Francisco</td>
                    <td>66</td>
                    <td>2009/01/12</td>
                    <td>$86,000</td>
                </tr>
           </tbody>
    <table>
    

    script-

        var editor; 
        $(document).ready(function() {
            editor = new $.fn.dataTable.Editor( {
            
            
            table: "#example",
            idSrc:  'Name',
            fields: [ {
                    label: "Name:",
                    name: "Name"
                }, 
                {
                    label: "Position:",
                    name: "Position"
                }, {
                    label: "Office:",
                    name: "Office"
                }, {
                    label: "Age:",
                    name: "Age"
                }, {
                    label: "Start date:",
                    name: "Start date",
                    type: "datetime"
                }, {
                    label: "Salary:",
                    name: "Salary"
                }
            ]
        } );
        
        // Activate an inline edit on click of a table cell
        $('#example').on( 'click', 'td', function (e) {
            //alert(this);
            editor.inline( this );
        } );
        
        
        $('#example').DataTable( {
            dom: "Bfrtip",
            columns: [
                { data: "Name", editField: "Name" },
                { data: "Position", editField: "Position" },
                { data: "Office", editField: "Office" },
                { data: "Age", editField: "Age" },
                { data: "Start date", editField: "Start date" },
                { data: "Salary", render: $.fn.dataTable.render.number( ',', '.', 0, '$' ) }
            ],
            select: {
                style:    'os',
                selector: 'td:first-child'
            },
            buttons: [
                { extend: "create", editor: editor },
                { extend: "edit",   editor: editor },
                { extend: "remove", editor: editor }
            ]
        } );
        
        
        
    } );
    
  • allanallan Posts: 63,252Questions: 1Answers: 10,420 Site admin

    Can you confirm if the link you gave at the top works for you please?

    I don't immediately see the issue with that code, I would need to see the page to be able to debug it, per our PM discussion.

  • bikram.b@bitordertech.combikram.b@bitordertech.com Posts: 7Questions: 2Answers: 0

    Allan,
    The link works for me but not functioning fully. I mean onclick of the cell the cell content shows in edit mode,but after changing the value and hitting 'enter' it shows up the error-
    'Cannot read property 'replace' of undefined'.

  • allanallan Posts: 63,252Questions: 1Answers: 10,420 Site admin

    My example is showing the 'Cannot read property 'replace' of undefined' error?

    What browser and OS are you using please?

    Allan

  • bikram.b@bitordertech.combikram.b@bitordertech.com Posts: 7Questions: 2Answers: 0

    I tested in-
    1- Chrome, Mac
    2-Chrome,Windows8

    Thanks

  • allanallan Posts: 63,252Questions: 1Answers: 10,420 Site admin

    Thanks. Could you possibly also answer my first question:

    Is my example is showing the 'Cannot read property 'replace' of undefined' error?

    I've added the "is" for clarity.

    Allan

  • bikram.b@bitordertech.combikram.b@bitordertech.com Posts: 7Questions: 2Answers: 0

    Yes I am following the example. And it is showing the above error.
    Thanks

  • allanallan Posts: 63,252Questions: 1Answers: 10,420 Site admin

    I'm asking if the error occurs for you when you are using that page. Not if it occurs on your own page, which we have already established.

    Basically, I currently have no way to reproduce the error, and therefore can't debug it. If the error can be reproduced on the page I linked to I need to know how to do it. I currently get no error on that page.

    Allan

  • bikram.b@bitordertech.combikram.b@bitordertech.com Posts: 7Questions: 2Answers: 0

    Hello Allan,
    Thank you very much for responding.
    The above link works perfectly fine for me. Im able to perform inline edit and save upon hitting enter. So you may not able to reproduce it there.

    We have included the trail version in our salesforce org(credentails shared in personal chat already) and are able to invoke inline edit on a cell. However upon hitting enter, we get the "'Cannot read property 'replace' of undefined' error" script error.

    We download the "JS+CSS only" library from trail page. Are we missing anything here. I went through the documentation and couldn't find whats missing in our integrated page.
    Can you please login to salesforce org and verify the pages link shared below.
    View Page : https://c.ap2.visual.force.com/apex/showAccounts
    Page Source : https://ap2.salesforce.com/09928000000DqaA

  • allanallan Posts: 63,252Questions: 1Answers: 10,420 Site admin

    Thanks - I've managed to log in this time and can see the issue.

    The problem is that the JSON response from the server is not in the format that Editor requires.

    Are you able to send back data in the JSON structure that Editor requires?

    Allan

This discussion has been closed.