initComplete

initComplete

mehtimehti Posts: 35Questions: 13Answers: 0
edited June 2015 in Free community support

Could someone help out. I have two pieces of code one works the other one doesn't.

Works:

$('#results').DataTable({
            "initComplete": function(settings, json) {
                $.each(json.data, function(index, value) {
                    $("#company").append('<option value="' + value.bank + '" selected="selected">' + value.bank + '</option>');
                    $("#frequency").append('<option value="' + value.provider + '" selected="selected">' + value.provider + '</option>');
                });

                $("#frequency").multipleSelect({
                    filter: true,
                    onUncheckAll: function() {
                        table.column(4).search("none", true).draw();
                    },
                    onCheckAll: function() {
                        table.column(4).search('').draw();
                    },
                    onClick: function() {
                        var value = "(";
                        $("ul li.selected").each(function(index, val) {
                            value += "(" + $(val).find('input').val() + ")|";
                        });
                        if (value == "(") {
                            value = "";
                        } else {
                            value = value.slice(0, -1);
                            value += ")";
                        }
                        table.column(4).search(value, true).draw();
                    }
                });

                $("#company").multipleSelect({
                    filter: true,
                    onUncheckAll: function() {
                        table.column(0).search("none", true).draw();
                    },
                    onCheckAll: function() {
                        table.column(0).search('').draw();
                    },
                    onClick: function() {
                        var value = "(";
                        $("ul li.selected").each(function(index, val) {
                            value += "(" + $(val).find('input').val() + ")|";
                        });
                        if (value == "(") {
                            value = "";
                        } else {
                            value = value.slice(0, -1);
                            value += ")";
                        }
                        table.column(0).search(value, true).draw();
                    }
                });
            }

However if I move the code into a function, it doesn't like this

$('#results').DataTable({
            "initComplete": function(settings, json) {
                setupFilter(json);
            }

The web page:
[retracted]

select Russia, RUB and amount 121 to get some results.

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,386Questions: 1Answers: 10,449 Site admin
    Answer ✓

    If you look in the console in your browser you will see a Javascript error:

    Uncaught ReferenceError: table is not defined

    You probably need to pass that variable through to the function or access the API some other way.

    Allan

  • mehtimehti Posts: 35Questions: 13Answers: 0

    Thanks Allan, i'll investigate.

This discussion has been closed.