Change titleAttr in language file

Change titleAttr in language file

kitcatkitcat Posts: 12Questions: 1Answers: 0

hi
i must change language of dataTable in 3 language

i used this code:

            text:       '<i class="fa fa-print"></i>',
            titleAttr:  'Print',
            autoPrint:  true,
            extend:     'print',

And i need change titleAttr in Language file

i used this but cant change

"buttons": {
    "print": {
        "text": "test text",
        "titleAttr": "test titleAttr"
    }
}

please help me

thank you

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 61,726Questions: 1Answers: 10,110 Site admin

    Unfortunately that it not something that is currently possible to change from the Ajax loaded JSON language file. You would need to get the language information (using i18n) after the initialisation is complete (initComplete) and either apply the attribute directly to the button or initialise the Buttons with that attribute at that point.

    Regards,
    Allan

  • kitcatkitcat Posts: 12Questions: 1Answers: 0

    hi
    thank you for anwser
    i read the manual completly and i know this solution
    if you can commit this problem
    that is very important for multi language users

    Regards.
    mousavi

  • allanallan Posts: 61,726Questions: 1Answers: 10,110 Site admin

    I agree and this is something I would like to see added myself. I hope to get a chance to implement it in future.

    Regards,
    Allan

  • kitcatkitcat Posts: 12Questions: 1Answers: 0
    edited January 2019

    hello again
    i dont know how use i18n
    but i use this code:

        "initComplete": function(settings, json) {
            let mtable = $('#table').DataTable();
    
            mtable.buttons().each(function (button, index) {
                console.log(button.node);
            });
        },
    

    but dont like this code and don't perform for buttons-colvis or buttons-page-length

    i need a loop for process all buttons and change that title
    if this loop can save to me parent and child (for buttons-colvis or buttons-page-length)
    that's very awesome

    are you can tips me?

  • kitcatkitcat Posts: 12Questions: 1Answers: 0
    edited January 2019

    i use this code but dont work for me

            mtable.buttons().i18n('buttons.copy', 'copy This!' );
    

    but i cant change titleAttr

  • kitcatkitcat Posts: 12Questions: 1Answers: 0

    I did not pay for this component
    but i think i must use i18n.edit
    and thats for sell
    are this true?

  • kitcatkitcat Posts: 12Questions: 1Answers: 0
    edited January 2019

    i use this

    mtable.button(index).text('copy this')
    

    OR

    mtable.button('button.copy').text('copy this');
    

    but cant acess to titleAttr

  • allanallan Posts: 61,726Questions: 1Answers: 10,110 Site admin

    No the titleAttr can't be updated dynamically - you need to update the node directly if you are using that technique:

    mtable.button(index).node().setAttribute( mtable.i18n('button.copy') );
    

    Allan

  • kitcatkitcat Posts: 12Questions: 1Answers: 0

    im sorry
    this code give me an error on mtable.i18n('button.copy')

    jquery.min.js:1 Uncaught TypeError: Cannot read property 'replace' of undefined
    at s.<anonymous> (datatables.min.js:180)
    at s.i18n (datatables.min.js:142)
    at m.fn.init.initComplete (functions.js:428)
    at datatables.min.js:115
    at Function.map (jquery.min.js:1)
    at r (datatables.min.js:115)
    at ua (datatables.min.js:88)
    at ha (datatables.min.js:88)
    at e (datatables.min.js:132)
    at b (datatables.min.js:112)

  • colincolin Posts: 15,144Questions: 1Answers: 2,586
    Answer ✓

    Hi @kitcat ,

    Yep, there was a mistake in that example, i18n() needs a second argument, so it should be

    table.button(0).node().attr( 'title', table.i18n( 'buttons.copy', 'Copy this!' ) );
    

    See live example here,

    Cheers,

    Colin

  • allanallan Posts: 61,726Questions: 1Answers: 10,110 Site admin

    Oops - thanks Colin!

  • kitcatkitcat Posts: 12Questions: 1Answers: 0

    thank you very much
    that is work for me

    i change my solution because my project does not have a powerful language manager
    but this topic is very helpful for the othe one

    thanks again

    best regards

This discussion has been closed.