Use selected data in display of a custom field type.

Use selected data in display of a custom field type.

adamclanceadamclance Posts: 3Questions: 0Answers: 0
edited December 2013 in Editor
Hello,
I have been using DataTables and Editor for a few weeks now, and I must say that you have a great product here! The issue that I'm having stems from custom field types. I have created a custom field type in order to utilize jquery sortable within the editor form. I can display a list of sortable elements just fine if I assign them myself, but I am trying to loop through a comma seperated list which is the mData of the field. I can get a handle on this data just fine within the set callback function and even alert it before showing the form, but since the form is created before my data is set, my sortable list is blank.

Is there any way that I can display the mData within my custom field type?

The code for my custom field is as follow:
[code]
// custom field type
$.fn.DataTable.Editor.fieldTypes.sortable = $.extend( true, {}, $.fn.DataTable.Editor.models.fieldType, {

"create": function ( sections_json ) {
var that = this;
if( oTT === null){
val = "hello, goodbye, so long, farewell";
var valueArray = val.split(",");
}
else{
var aData = oTT.fnGetSelectedData();
sections_json = aData[0]['sections_json'];
alert(sections_json);
val = sections_json;
var valueArray = val.split(",");
}

var string = "";
for(var i=0; i

Replies

  • allanallan Posts: 61,716Questions: 1Answers: 10,108 Site admin
    Hi Adam,

    Thanks for your kind words!

    In the `set()` function above, it doesn't look like `val` is being used at all - that is presumably the comma separated list is it? It sounds like what you might want to do is break your CSVs into an array, inject them into the document and then use sortable's `refresh` function ( http://api.jqueryui.com/sortable/#method-refresh ).

    Perhaps something like:

    [code]
    set: function ( sections_json, val ) {
    var a = val.split( ', ' );

    sections_json._input
    .empty()
    .append( $(a).wrap( '' ) )
    .sortable( 'refresh' );
    }
    [/code]

    Then you get the values you might use:

    [code]
    get: function ( sections_json, val ) {
    return sections_json._input.children().map( function () {
    return $(this).text();
    } ).join( ', ' );
    }
    [/code]

    I haven't tested it, so I might have a daft syntax error somewhere, but I think that should work... YOu could remove the 'So long..' part of your code in the initialiser part since that now isn't needed.

    Let me know how you get on with it!

    Regards.
    Allan
  • adamclanceadamclance Posts: 3Questions: 0Answers: 0
    Hi Allan,
    Thanks for the response!
    Your answer seems like it would do the trick, but I am now getting: Uncaught TypeError: Object # has no method 'empty' when the set callback is run.

    Any ideas?

    Thanks again for the help,
    -Adam
This discussion has been closed.