Hidden attributes on Datatables

Hidden attributes on Datatables

charly_spencecharly_spence Posts: 4Questions: 0Answers: 0
edited July 2012 in General
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

Replies

  • allanallan Posts: 63,535Questions: 1Answers: 10,475 Site admin
    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
  • charly_spencecharly_spence Posts: 4Questions: 0Answers: 0
    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
  • charly_spencecharly_spence Posts: 4Questions: 0Answers: 0
    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: 63,535Questions: 1Answers: 10,475 Site admin
    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:

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

    Allan
  • charly_spencecharly_spence Posts: 4Questions: 0Answers: 0
    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: 63,535Questions: 1Answers: 10,475 Site admin
    Excellent - good to hear that helped. And thanks for the beer :-)

    Allan
This discussion has been closed.