Field Labels

Field Labels

indymxindymx Posts: 63Questions: 3Answers: 0

I have done this before, but I have forgotten how..

I have a "status" field in my db that is an 'int'. On the Editor modal and bubble edit it shows my label "active | inactive", however I'd like to display that on the page that displays the table.

Can someone remind me how to accomplish this?

This question has an accepted answers - jump to answer

Answers

  • indymxindymx Posts: 63Questions: 3Answers: 0
    edited May 2016

    this is my current setup..

    (function ($) {
    
    $(document).ready(function () {
        var editor = new $.fn.dataTable.Editor({
            ajax: '/php/table.links.php',
            table: '#links',
            fields: [
                {
                    "label": "Link",
                    "name": "link"
                },
                {
                    "label": "Status",
                    "name": "status",
                    "type": "radio",
                    "options": [
                        {
                            "label": "Active",
                            "value": "1"
                        },
                        {
                            "label": "Inactive",
                            "value": "0"
                        }
    
                    ]
                }
            ]
        });
        $('#links').on('click', 'tbody td:not(:first-child)', function (e) {
            editor.bubble(this);
        });
        var table = $('#links').DataTable({
            dom: 'Bfrtip',
            ajax: '/php/table.links.php',
            columns: [
                {
                    data: null,
                    defaultContent: '',
                    className: 'select-checkbox',
                    orderable: false
                },
                {
                    "data": "link"
                },
                {
                    "data": "status"
                }
            ],
            select: {
                style: 'os',
                selector: 'td:first-child'
            },
            lengthChange: false,
            buttons: [
                {extend: 'create', editor: editor},
                {extend: 'remove', editor: editor}
            ]
        });
    });
    

    }(jQuery));

  • allanallan Posts: 63,516Questions: 1Answers: 10,473 Site admin

    A renderer is what you want here. Simply have it return the value you want based on the underlaying data.

    Allan

  • indymxindymx Posts: 63Questions: 3Answers: 0

    are there any examples of what I am trying to accomplish?

    I read thru that page and didn't really see anything that does what I'm looking for. I could be dumb. ;)

  • allanallan Posts: 63,516Questions: 1Answers: 10,473 Site admin
    edited May 2016 Answer ✓
    render: function ( data, type, row ) {
      return data == 1 ? 'Active' : 'Inactive';
    }
    

    Allan

  • indymxindymx Posts: 63Questions: 3Answers: 0

    Oh.. simple.. Thanks Allan

This discussion has been closed.