locked
JAVASCRIPT NOT WORK in .JS file RRS feed

  • Question

  • User31164289 posted

    I have a web app with master page. In Masterpage using control Scriptmanager to include all javascript file.

    One of these files contains instructions for initializing some of the controls I have on the pages. Everything seemed to be working properly:

    function pageLoad() {
        $('[data-plugin="switchery"]').each(function (idx, obj) {
    
            if ($(this).prop("tagName") == "SPAN" && $(this).find("input[type=checkbox]:first").prop("tagName") == "INPUT") {
                var chk = $(this).find("input[type=checkbox]");
                new Switchery(chk[0], $(this).data());
            } else {
                new Switchery($(this)[0], $(this).data());
            }
        });
        
        $('.selectpicker').selectpicker();
    
    $(document).ready(function () {
        var a = $("#datatable-buttons").DataTable({
            lengthChange: !1,
            responsive: true,
            buttons: ["copyHtml5", "excelHtml5", "csvHtml5", "pdfHtml5"],
            language: {
                paginate: {
                    previous: "<i class='mdi mdi-chevron-left'>",
                    next: "<i class='mdi mdi-chevron-right'>"
                }
            }        
        });
        a.buttons().container().appendTo("#datatable-buttons_wrapper .col-md-6:eq(0)");
        
    });
    
        
        $('[data-toggle="select2"]').select2();
    
       
    }

    Now I need to add a new initialization instruction of a control (datatable) with parameters different from the one already present. In this case, however, it does not seem to work:

    function pageLoad() {
        $('[data-plugin="switchery"]').each(function (idx, obj) {
    
            if ($(this).prop("tagName") == "SPAN" && $(this).find("input[type=checkbox]:first").prop("tagName") == "INPUT") {
                var chk = $(this).find("input[type=checkbox]");
                new Switchery(chk[0], $(this).data());
            } else {
                new Switchery($(this)[0], $(this).data());
            }
        });
        
        $('.selectpicker').selectpicker();
    
    $(document).ready(function () {
        var a = $("#datatable-buttons").DataTable({
            lengthChange: !1,
            responsive: true,
            buttons: ["copyHtml5", "excelHtml5", "csvHtml5", "pdfHtml5"],
            language: {
                paginate: {
                    previous: "<i class='mdi mdi-chevron-left'>",
                    next: "<i class='mdi mdi-chevron-right'>"
                }
            }        
        });
        a.buttons().container().appendTo("#datatable-buttons_wrapper .col-md-6:eq(0)");
        
    });
    
    $(document).ready(function () {
            $("#datatable-nobuttons").DataTable({
                lengthChange: !1,
                responsive: true,
                "bFilter": false,
                "paging": false,
                "ordering": false
    
            });
    });
    
        $('[data-toggle="select2"]').select2();
    
       
    }

    Table with id=datatable-nobuttons" not apply plugin datatable.

    What am I doing wrong?

    Sunday, April 5, 2020 8:36 AM

All replies

  • User288213138 posted

    Hi clembo67,

    Now I need to add a new initialization instruction of a control (datatable) with parameters different from the one already present. In this case, however, it does not seem to work:

    $(document).ready(function () {
            $("#datatable-nobuttons").DataTable({
                lengthChange: !1,
                responsive: true,
                "bFilter": false,
                "paging": false,
                "ordering": false
    
            });
    });

    I tested this code, it works fine in my side. 

    Without your html code, I cannot reproduce your problem.

    But you can use F12 to check if there are any error message in the console and dubug your code.

    If you still can't solve the problem, please post your complete code.

    Best regards,

    Sam

    Monday, April 6, 2020 6:44 AM