How to get a value from a row on edit

How to get a value from a row on edit

whitbaconwhitbacon Posts: 40Questions: 2Answers: 0
edited June 2013 in Editor
I am trying to dynamically update a select box.
[code]
editor.on('onInitEdit', function () {

alert (editor.get('userid');
$(editor.field('caseinfo.agencyid').update(agencyloader()));
$(editor.field('userid').update(userloader(editor.get('caseinfo.agencyid'))));

} );

[/code]

The problem is I am getting defaults from the editor form. and not values in the row. How would I get the values from the row for the edit event?

I have the alart just to see what I was getting?

Replies

  • allanallan Posts: 61,446Questions: 1Answers: 10,054 Site admin
    You could possibly use `this.s.editRow` which is the node of the row being edited (so you could use with then fnGetData etc). Generally using the settings (s) variables isn't recommended, and setting them certainly is not, but you should be okay here. I think the onInit* events should be passing in the rows that are being acted upon. I'll add that for the next release. Thanks for the suggestion.

    Having said that - is `editor.get('caseinfo.agencyid')` giving you the default? That shouldn't be the case. The values are set before onInitEdit is executed.

    Regards,
    Allan
  • whitbaconwhitbacon Posts: 40Questions: 2Answers: 0
    I tried this it did not work.
    [code]

    editor.on('onInitEdit', function () {
    oTable = $('#caseinfo').dataTable();
    var sData = oTable.fnGetData.editrow;
    alert( 'The cell clicked on had the value of '+sData[0] );

    } );

    [/code]


    I don't really get it. Sorry I haven't quite wrapped my mind around the datatables framework, but am getting closer?


    Thanks
  • whitbaconwhitbacon Posts: 40Questions: 2Answers: 0
    I also tried this:
    [code]
    editor.on('onInitEdit', function () {
    oTable = $('#caseinfo').dataTable();
    var sData = oTable.$('tr').fnGetData(this.s.editrow);
    alert( 'The cell clicked on had the value of '+sData[0] );

    } );

    [/code]
  • allanallan Posts: 61,446Questions: 1Answers: 10,054 Site admin
    edited June 2013
    Try this:

    [code]
    editor.on('onInitEdit', function () {
    oTable = $('#caseinfo').dataTable();
    var sData = oTable.fnGetData(this.s.editRow);
    alert( 'The cell clicked on had the value of '+sData[0] );
    } );
    [/code]

    Allan
  • whitbaconwhitbacon Posts: 40Questions: 2Answers: 0
    My alert comes back and says:

    The cell clicked on had the value of undefined
  • whitbaconwhitbacon Posts: 40Questions: 2Answers: 0
    i tried it here as well without joins:

    [code]

    (function($){

    $(document).ready(function() {
    var editor = new $.fn.dataTable.Editor( {
    "ajaxUrl": "php/table.agencies.php",
    "domTable": "#agencies",
    "fields": [
    {
    "label": "Agency Name",
    "name": "agencyname",
    "type": "text"
    },
    {
    "label": "Address",
    "name": "agencyaddress",
    "type": "text"
    },
    {
    "label": "City",
    "name": "agencycity",
    "type": "text"
    },
    {
    "label": "State",
    "name": "agencystate",
    "type": "text"
    },
    {
    "label": "Zip",
    "name": "agencyzip",
    "type": "text"
    },
    {
    "label": "Phone",
    "name": "agencyphone",
    "type": "text"
    },
    {
    "label": "Notes",
    "name": "agencynotes",
    "type": "text"
    }
    ]
    } );

    editor.on('onInitEdit', function () {
    oTable = $('#agencies').dataTable();
    var sData = oTable.fnGetData(this.s.editRow);
    alert( 'The cell clicked on had the value of '+sData[1] );
    } );



    $('#agencies').dataTable( {
    "sDom": "Tfrtip",
    "sAjaxSource": "php/table.agencies.php",
    "aoColumns": [
    {
    "mData": "agencyname"
    },
    {
    "mData": "agencyaddress"
    },
    {
    "mData": "agencycity"
    },
    {
    "mData": "agencystate"
    },
    {
    "mData": "agencyzip"
    },
    {
    "mData": "agencyphone"
    },
    {
    "mData": "agencynotes"
    }
    ],
    "oTableTools": {
    "sRowSelect": "multi",
    "aButtons": [
    { "sExtends": "editor_create", "editor": editor },
    { "sExtends": "editor_edit", "editor": editor },
    { "sExtends": "editor_remove", "editor": editor }
    ]
    }
    } );
    } );

    }(jQuery));
    [/code]
  • allanallan Posts: 61,446Questions: 1Answers: 10,054 Site admin
    > sData[1]

    sData[1] is undefined. Do you mean `sData.agencyaddress` ? It is an object that you have in your data source (based upon your DataTables initialisation), not an array.

    Allan
This discussion has been closed.