Bootstrap Switch and DataTable

Bootstrap Switch and DataTable

gidabangidaban Posts: 1Questions: 0Answers: 0

Hello all,

In my Admin Panel i use 2 plugins for display data from Database:

1 - Bootstrap Switch 2 - DataTable

So far i don't have problems with Datatable and display it, but i want to add one column with swith button for change status of featured post, script working only on first page. After change page "BootstrapSwitch" don't working. :/

My code is below.

 $('#posts').DataTable({
                "order": [[1, "asc"]],
                "aoColumns": [
                    null,
                    null,
                    null,
                    {"bSortable": false, "bSearchable": false},
                    null, {"bSortable": false, "bSearchable": false},
                    null,
                    null,
                    {"bSortable": false, "bSearchable": false}
                ]
            });
            $('.grid-switch-released').bootstrapSwitch({
                size: 'small',
                onText: 'YES',
                offText: 'NO',
                onColor: 'primary',
                offColor: 'default',
                onSwitchChange: function (event, state) {

                    $(this).val(state ? 'on' : 'off');

                    var pk = $(this).data('key');
                    var value = $(this).val();
                    var publishDate = $('[data-published-id="' + pk + '"]');
                    var featureDate = $('[data-featured-id="' + pk + '"]');

                    var action = $(this).data('action');
                    $.ajax({
                        url: "/admins/posts/" + pk,
                        type: "POST",
                        data: {
                            released: value,
                            action: action,
                            _token: '{{csrf_token()}}',
                            _method: 'PUT'
                        },
                        success: function (data) {
                            if (data.action == "publish") {
                                publishDate.html(data.date);
                            } else {
                                featureDate.html(data.date);
                            }
                            toastr.success(data.message);
                        }
                    });
                }
            });
This discussion has been closed.