idSrc not working?

idSrc not working?

snunnsnunn Posts: 17Questions: 5Answers: 0

I am trying to use: idSrc: "idEntity" on the Editor. Whenever I edit a row, and hit submit the id is not being set as shown in the documentation. I can see: action=edit&data...etc, but never see the identity or id field being passed.

Answers

  • bvelasquezbvelasquez Posts: 28Questions: 7Answers: 0

    Same here, I am using a web service connected to a db with two forien keys forming a composite key. But I can't seem to define the edit/remove functions because it always kicks back an error:

    https://datatables.net/manual/tech-notes/14

    Here is what I have tried:

    datatables_editor = new $.fn.dataTable.Editor({
        ajax: {
            create: {
                type: 'POST',
                url:  devUrlEndpoint
            },
            edit: {
                type: 'PUT',
                url:  devServerRelativeURL + "api/TimesheetClocks/"
            },
            remove: {
                type: 'DELETE',
                url:  devServerRelativeURL + "api/TimesheetClocks/"
            }
        },
        table: '#myTable',
        fields: [
            { label: 'UserID', name: 'UserID', def: currentUsername },
            { label: 'Work Date', name: 'WorkDateKey', def: currentDate },
            { label: 'ClockIn',  name: 'ClockIn' },
            { label: 'ClockOut', name: 'ClockOut' },
            { label: 'Lunchbreak',  name: 'Lunchbreak'  },
            { label: 'Hours',  name: 'Hours'  },
            { label: 'Comments',  name: 'Comments'  }
        ],
        idSrc: [
            { "data": "UserID" },
            { "data": "WorkDateKey" }
        ]
    });    
    
  • snunnsnunn Posts: 17Questions: 5Answers: 0

    All I have is: idSrc: 'idEntity',

  • snunnsnunn Posts: 17Questions: 5Answers: 0

    I decided to work around this issue for now. I ended up putting my key in the editor as a hidden field. Then I added the following code:

    editor.on( 'preSubmit', function ( e, o, action ) {
            var id = editor.field( 'idEntity' );
            o.idEntity = id.val();  // create a new parameter to pass over to the server called entityId
    
    
        } );
    

    This resulted in a field called identity being passed along with the action, and data fields. Works for now.

  • allanallan Posts: 63,535Questions: 1Answers: 10,475 Site admin

    The ID isn't submitted as a field, but rather it is submitted as part of the parameter name. For example, your client-side might submit the following on edit:

    action                   = edit
    data[row_29][extn]       = 2947
    data[row_29][first_name] = Fiona
    data[row_29][last_name]  = Green
    data[row_29][office]     = San Francisco
    data[row_29][position]   = Chief Operating Officer (COO)
    data[row_29][salary]     = 850000
    data[row_29][start_date] = 2010-03-11
    

    In this case row_29 is the id.

    Allan

  • snunnsnunn Posts: 17Questions: 5Answers: 0

    Allan,
    Thanks for the note, that is what I noticed when I was debugging. However, it makes it hard to quickly get parameters on the server since the "parameter name" becomes request unique since there is a changing key in the parameter name. For example, I am trying to get the parameter using the session object via server side javascript such as:

    return $exchange.request().getParameter("data["+keyId+ "]["+keyName+"]");

    However, since the key wasn't passed separately, I would have had to parse it out of one of the parameters that was posted up in the body. So, for my case, having the key also passed allows me to quickly get the parameter without much difficulty for a single row update.

This discussion has been closed.