DataTables logo DataTables

via Ad Packs
Hidden attributes on Datatables
  • Hello,
    I have 2 hidden attributes -"type": "hidden"- in a Editor datatable which I'd like to populate by applying some logic based on the user selection on the rest of the other columns.
    Which API, plugin or callback function should I use? to save the hidden attributes into the server when the user either edits or creates a row?

    Charles
  • allanallan
    Posts: 15,472
    Hi Charles,

    Sounds like it is the set API method that you will need, which is documented here: http://editor.datatables.net/api/#set .

    Allan
  • Hello
    I tried by using 'onSetData', but it only works on the client side, nothing is sent to the database for the hidden column (the other columns update just correct)

    Thanks
  • Hello,
    Anyone that can put you on the right track or provide an example on how to achieve what I'm describing?

    I'll invite a beer on that
  • allanallan
    Posts: 15,472
    Hi Charles,

    At what point do you want the values to be set for what you are sending to the server? If you want them read from somewhere when the submission is done, what you could do is use the onPreSubmit event:

    editor.on('onPreSubmit', function ( json ) {
      json.data.myProp1 = $('#myVal1').val();
      json.data.myProp2 = "hello world";
    } );
    

    Allan
  • Thanks Allan,
    That made the trick, I used the following approach on the table.test.js:

    var editor = new $.fn.dataTable.Editor( {
    {
    "ajaxUrl": "",
    "domTable": "#test",
    "fields": [
    ...
    ],
    "events": {
    "onPreSubmit": function (json) {
    json.data.test_id = "test@test.com";
    }
    }
    } );

    I already honored my commitment under the account from Jose Hurtado.
    Regards
  • allanallan
    Posts: 15,472
    Excellent - good to hear that helped. And thanks for the beer :-)

    Allan

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Support

Get useful and friendly help straight from the source.

In this Discussion