How can I set default values for buttons

How can I set default values for buttons

aschippersaschippers Posts: 22Questions: 8Answers: 3
edited March 2016 in Buttons

I want to set '<i fa fa-edit'></i>' for the edit button in the defaults section.

The setting of defaults works, but setting values for buttons doesn't work. It still gives new, edit, delete.

I can't find the solution in the documentation.

$.extend( true, $.fn.dataTable.Buttons.defaults, {
    buttons: [
        { 
            extend: 'create', 
            name: 'test01'
        },
        { extend: 'edit',
        name: 'test02'
        }
    ]
});

$.extend( true, $.fn.dataTable.defaults, {
    dom: 'Bfrti',
    responsive: true,
    processing: true,
    serverside: true,
    select: true,
    rowId: 'id',
        buttons: [
        { 
            extend: 'create', 
            name: 'testj2e'
        },
        { extend: 'edit',
        name: 'gaap'
        }
    ],
    select: {
        style: 'os',
        selector: 'td:first-child'
    },
    "width": "90%",
    "height": "100%"
}); 

    area_roles = $('#area_roles').DataTable ( {
        // dom: 'Bfrti',
        // responsive: true,
        // processing: true,
        // serverside: true,
        // select: true,
        ajax: {
            url: '/areas/'+ document.getElementById("area_roles").getAttribute("area_id") +'/area_roles.json',
            type: 'GET'
        },
        // rowId: 'id',
        columns: [ 
            {
                data: null,
                defaultContent: '',
                className: 'select-checkbox',
                orderable: false
            }, 
            { data: 'name' },
            { data: 'description' },
            { editField: 'asset_required',
              render: function(d,type,row) {
                if (row.asset_required == "1") {
                    return '<i class="fa fa-check"></i>';
                } else {
                    return '<i class="fa fa-minus"></i>';
                }
            } },
            { editField: 'product_required',
              render: function(d,type,row) {
                if (row.product_required == "1") {
                    return '<i class="fa fa-check"></i>';
                } else {
                    return '<i class="fa fa-minus"></i>';
                }
            } }
        ],
        buttons: [ {
            extend: 'create',
            editor: editor
        }, {
            extend: 'edit',
            editor: editor
        }, {
            extend: 'remove',
            editor: editor
        }],
        order: [1, 'asc'],
        select: {
            style: 'os',
            selector: 'td:first-child'
        },
        "width": "90%",
        "height": "100%"
    });

This question has accepted answers - jump to:

Answers

  • allanallan Posts: 63,489Questions: 1Answers: 10,469 Site admin
    Answer ✓

    The default isn't used in the above since you se the buttons option in your DataTables configuration object. That takes priority, which is why you see all three buttons.

    Allan

  • aschippersaschippers Posts: 22Questions: 8Answers: 3

    Is it possible in another way, to define the text value of a button "somewhere" as default and only extend the fields you need in the DataTables Configuration object?

    Or should i try to do this through the i18n option and set the text as a default text over there?

  • allanallan Posts: 63,489Questions: 1Answers: 10,469 Site admin
    Answer ✓

    The i18n options in this case are the way to do it. Normally you could use the Button defaults for that, but since the value actually comes form Editor for the Editor buttons, it needs to be set there.

    Allan

This discussion has been closed.