Custom form in Editor

Custom form in Editor

HornistHornist Posts: 9Questions: 1Answers: 0
edited August 2013 in Editor
I am using Editor on one of my Datatables. The ultimate scenario I want to pull together is to have a custom form come up for edit/new. This form would incorporate an existing library of JQuery/CSS. The form could be loaded via an AJAX call.

I am not 100% certain how to approach this in the optimal way though. Is there an existing example or pattern for this?

Replies

  • allanallan Posts: 63,498Questions: 1Answers: 10,470 Site admin
    This is a slightly daft question and I might be shooting myself in the foot here, but if you have a custom form, what do you want to get from Editor? On the client-side Editor is basically just a form generator / display tool. Yes it is a little bit more than that, in that you can customise fields and it interfaces directly with DataTables, but the DataTables API is public ( http://datatables.net/api ) and any customisation options in Editor wouldn't be available with a custom form.

    Having said that, if you do want to use Editor, what I would suggest you do is use the `set` method to set the values for the fields in the Editor based on the values from the custom form with the `edit` and `create` functions being used to set the form up, but without display the Editor form.

    Allan
  • HornistHornist Posts: 9Questions: 1Answers: 0
    Been looking in forums too. I think what I want is actually a hidden id column, and something akin to:
    [code]
    $('#myTable').on('click', 'tr', function(event) {
    $('#myTable').fnGetData(this);
    }).on('dblclick', 'td', function(event) {
    $(this).css('background', '#000');
    var id = $('#myTable').fnGetData(this)[0];
    displaySomeForm(id);
    });
    [/code]
  • allanallan Posts: 63,498Questions: 1Answers: 10,470 Site admin
    That's fine - you can do that :-). I should say that using click and dblclick on the same element is not generally recommended: http://www.quirksmode.org/dom/events/click.html - but the basic idea looks okay.

    Allan
  • HornistHornist Posts: 9Questions: 1Answers: 0
    Alan, I thought I had this one, but I get the following error:

    Uncaught TypeError: Object [object Object] has no method 'fnGetData'

    The code is essentially the same as above. Can you point me in the right direction?
  • allanallan Posts: 63,498Questions: 1Answers: 10,470 Site admin
    Try:

    [code]
    $('#myTable').dataTable().fnGetData(this)[0];
    [/code]

    fnGetData is a DataTables API call, not a jQuery one.

    Regards,
    Allan
This discussion has been closed.