localization

localization

maxdiablemaxdiable Posts: 6Questions: 3Answers: 0

hi,
i use:

$('#table-log').DataTable({
"language": {
"url": "//cdn.datatables.net/plug-ins/1.10.18/i18n/Italian.json"
},
});

but the localization not working.

any help?

br max

Answers

  • kthorngrenkthorngren Posts: 21,350Questions: 26Answers: 4,955

    Your config seems to work here:
    http://live.datatables.net/qubowuda/1/edit

    Maybe something in your environment is causing the issue. Have you verified the Italian.json is being downloaded?

    Kevin

  • maxdiablemaxdiable Posts: 6Questions: 3Answers: 0
    edited June 2018

    hi,
    i put the same code:

    <script>
        $(document).ready(function () {
            $('.table-container tr').on('click', function () {
                $('#' + $(this).data('display')).toggle();
            });
            $('#table-log').DataTable({
                "language": {
                    "url": "//cdn.datatables.net/plug-ins/1.10.18/i18n/Italian.json"
                },
                "order": [$('#table-log').data('orderingIndex'), 'desc'],
                "stateSave": true,
                "stateSaveCallback": function (settings, data) {
                    window.localStorage.setItem("datatable", JSON.stringify(data));
                },
                "stateLoadCallback": function (settings) {
                    var data = JSON.parse(window.localStorage.getItem("datatable"));
                    if (data)
                        data.start = 0;
                    return data;
                },
            });
            $('#delete-log, #delete-all-log').click(function () {
                return confirm('Are you sure?');
            });
        });
    </script>
    

    EDIT: Formatted JS code using Markdown

    but no working :(

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

  • maxdiablemaxdiable Posts: 6Questions: 3Answers: 0

    hi,
    the firefox debug show this error:

    SyntaxError: JSON.parse: unexpected end of data at line 1 column 1 of the JSON data

    any help?

    br
    max

  • kthorngrenkthorngren Posts: 21,350Questions: 26Answers: 4,955

    I copied your Datatables code here and it is still working:
    http://live.datatables.net/mavapomu/1/edit

    Does your table work if you remove the language option?

    You can try the torubleshooting steps at this link to see what is being returned:
    https://datatables.net/manual/tech-notes/1

    Kevin

  • allanallan Posts: 63,542Questions: 1Answers: 10,476 Site admin

    It suggests that window.localStorage.getItem("datatable") is returning nothing - perhaps on the first load, or perhaps somehow invalid JSON got into it. Try:

                "stateLoadCallback": function (settings) {
                    try {
                      var data = JSON.parse(window.localStorage.getItem("datatable"));
                      if (data)
                        data.start = 0;
                      return data;
                    }
                    catch ( e ) {
                      return {};
                    }
                },
    

    Allan

  • maxdiablemaxdiable Posts: 6Questions: 3Answers: 0

    i changed my code:

    $('#table-log').DataTable({
    "language": {
    "url": "//cdn.datatables.net/plug-ins/1.10.18/i18n/Italian.json"
    },
    });

    datatable show data, but the language not loading, firefox show the same error:

    SyntaxError: JSON.parse: unexpected end of data at line 1 column 1 of the JSON data

    br
    Max

  • maxdiablemaxdiable Posts: 6Questions: 3Answers: 0

    i working width laravel:
    and the chromwe show this error:

    Failed to load http://cdn.datatables.net/plug-ins/1.10.18/i18n/Italian.json: Request header field X-CSRF-TOKEN is not allowed by Access-Control-Allow-Headers in preflight response.

    br
    Max

  • allanallan Posts: 63,542Questions: 1Answers: 10,476 Site admin

    That's correct - you shouldn't be sending your CSRF token to a third party server. Doing so is a security issue since it would make it trivial to steal and then leave your service open to a CSRF attack (i.e. completely mitigating any benefit of using a CSRF token in the first place!).

    Allan

This discussion has been closed.