How can I configure language and options?

How can I configure language and options?

lat94lat94 Posts: 11Questions: 2Answers: 0

I can't figure out where to put the Data Table translations/options settings.
I am getting an error (obviously) of "reinitialize" the table, which completely makes sense.
Can somebody help me?

Code untill now:

$(document).ready(function(){
        $('#myTable').DataTable({
          "language": {
              "url": "http://cdn.datatables.net/plug-ins/9dcbecd42ad/i18n/Portuguese-Brasil.json"
          }  
          });

      });

      $(document).ready(function(){
        $('#myTable').DataTable({            
                    
          "lengthMenu": false,               
          "bLengthChange": false,
          "scrollX": true

        });    

    });

error:

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 21,343Questions: 26Answers: 4,954

    Did you read through the tech note linked in the error?
    https://datatables.net/manual/tech-notes/3

    The tech note has the answer. Post back if it doesn't help.

    Kevin

  • lat94lat94 Posts: 11Questions: 2Answers: 0
    edited February 2018

    Yes, I did already checked this link. And it is not working with the parameter "retrieve: true".
    Thanks for answering!

  • kthorngrenkthorngren Posts: 21,343Questions: 26Answers: 4,954

    You need to combine the initialization parameters into one, like this:

            $('#myTable').DataTable({           
              "language": {
                  "url": "http://cdn.datatables.net/plug-ins/9dcbecd42ad/i18n/Portuguese-Brasil.json"
              },                      
              "lengthMenu": false,              
              "bLengthChange": false,
              "scrollX": true
     
            });   
    

    Otherwise the second one will cause the reinitialization error.

    Kevin

  • tangerinetangerine Posts: 3,365Questions: 39Answers: 395

    Why don't you put the "language" initialisation into your second block of code, and then scrap your first block?

  • lat94lat94 Posts: 11Questions: 2Answers: 0

    @kthorngren , I already tried this way and won't work

    code:

    <script type="text/javascript">     
    
    
          $(document).ready(function(){
            $('#myTable').DataTable({ 
    
              "language": {
                  "url": "http://cdn.datatables.net/plug-ins/9dcbecd42ad/i18n/Portuguese-Brasil.json"
              },                     
              "lengthMenu": false,             
              "bLengthChange": false,
              "scrollX": true
    
            });    
    
        });
         
          
        </script>
    

    Error:

    Uncaught TypeError: h.ajax is not a function
    at HTMLTableElement.<anonymous> (jquery.dataTables.min.js:88)
    at Function.each (jquery-3.1.1.slim.min.js:2)
    at r.fn.init.each (jquery-3.1.1.slim.min.js:2)
    at r.fn.init.m [as dataTable] (jquery.dataTables.min.js:82)
    at r.fn.init.h.fn.DataTable (jquery.dataTables.min.js:164)
    at HTMLDocument.<anonymous> (DataTable-jQuery.html:267)
    at j (jquery-3.1.1.slim.min.js:2)
    at k (jquery-3.1.1.slim.min.js:2)

  • lat94lat94 Posts: 11Questions: 2Answers: 0

    @tangerine , could you elaborate some code to exemplify, please?

  • tangerinetangerine Posts: 3,365Questions: 39Answers: 395

    My answer is the same as @kthorngren's answer.

  • kthorngrenkthorngren Posts: 21,343Questions: 26Answers: 4,954
    Answer ✓

    Your code works here:
    http://live.datatables.net/recidesu/1/edit

    Can you post a link to your page showing the issue?

    Kevin

  • lat94lat94 Posts: 11Questions: 2Answers: 0

    @kthorngren yeah your code is working and that's really weird :worried:

    Here is my code (not working after inserting "language": https://jsfiddle.net/t6n2u5sx/1/

  • lat94lat94 Posts: 11Questions: 2Answers: 0

    I was able to get your code working here too. But when I put bootstrap-4 styling it gives the error mentioned above > "Uncaught TypeError: h.ajax is not a function"

    Bootstrap 4 styling:
    <link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.10.16/css/dataTables.bootstrap4.min.css">

  • tester1234tester1234 Posts: 2Questions: 0Answers: 0

    I'm having the same problem with bootstrap4

  • kthorngrenkthorngren Posts: 21,343Questions: 26Answers: 4,954
    edited February 2018

    Found this SO thread. You are using this:

     <script src="https://code.jquery.com/jquery-3.1.1.slim.min.js" integrity="sha384-A7FZj7v+d/sdmMqp/nOQwliLvUsJfDHW+k9Omg/a/EheAdgtzNs3hpfag6Ed950n" crossorigin="anonymous"></script>
    

    Sounds like you do not want to use the slim version. BTW you also are loading jQuery at the top of the fiddle. You will only want to load it once.

    Kevin

  • lat94lat94 Posts: 11Questions: 2Answers: 0

    @kthorngren yeah, about the slim version I forgot to take it off of my copy version which I uploaded to jsfiddle.
    Anyway, I've managed to get it done with you guys helping me, thanks!

    Code with DataTable working exactly how I want to:
    live.datatables.net/jijurapu/1/edit

  • tester1234tester1234 Posts: 2Questions: 0Answers: 0

    @lat94 works like a charm, thank you!

This discussion has been closed.