select fields type

select fields type

netliteITnetliteIT Posts: 6Questions: 1Answers: 0

Hi i use in data tables a static select menu sometring like.

type: "select",
options: [
{ label: "Z", value: 1 },
{ label: "Y", value: 2 },
{ label: "X", value: 3 }
]

I don't be able to show field label , datatables always show filed value.

I use render: with 3 condition con value and everything is ok, but there isn't a better way to do this more clear ?

In editor everything is ok label i showing without "if".

This question has an accepted answers - jump to answer

Answers

  • colincolin Posts: 9,834Questions: 0Answers: 1,632

    Is this using Editor? This example may help.

    If that doesn't help, I didn't fully understand your question, so could you link to your page of modify this test case to demonstrate the problem please,

    Colin

  • netliteITnetliteIT Posts: 6Questions: 1Answers: 0
    edited June 15

    Hi thank for your help, my problem is related to the Datatables not to the editor. Datatables Show fields value not Label value of select type.
    In datatables i defined the select like this

    var table = $('#example').DataTable( {
            lengthChange: false,
            ajax: "rest/example/",
            columns: [
            { data: "tablename.examples",
                    type:  "select",
                    options: [
                       { label: "Z", value: 1 },
                       { label: "Y", value: 2 },
                       { label: "X", value: 3 }
           ]}........
    

    I need to do

    columnDefs: [
    "targets": [ 12 ], //(refer to the fields "tablename.examples")
    data: null, 
    render: function ( data, type, row, meta ) {
                                if(data == 1)
                                            return "Z";
                                if(data == 2)
                                            return "Y";
                                if(data == 3)
                                            return "X";
                                if(data == 0 || data == '')
                                            return "";
                           }
    ]
    

    to make datatables grid showing correctly label and not values.

    There is a better method without use of "render: function"?
    I prefer do not make too much "if" condition in my code.
    Thanks a lot

    Edited by Colin - Syntax highlighting. Details on how to highlight code using markdown can be found in this guide.

  • colincolin Posts: 9,834Questions: 0Answers: 1,632
    Answer ✓

    columns.type doesn't have a select option, that's only for Editor's fields.type.

    What you're doing is probably correct if you just want the static value being shown, otherwise yep, you could return the HTML for the select in columns.render (there are a few examples on that page doing that),

    Colin

  • netliteITnetliteIT Posts: 6Questions: 1Answers: 0

    Hi Colin, thanks

Sign In or Register to comment.