Triggering the action method of a button when returning to the page containing the grid?

Triggering the action method of a button when returning to the page containing the grid?

jstemperjstemper Posts: 15Questions: 10Answers: 0

I have several filter buttons on my grid. When one of the filter buttons is selected I redraw the button text to show a filter icon. When the user goes to the record detail from the grid I persist the filter selection so that the filter stays in place when the user returns. My question is how do I redraw the button to show the filter icon?

My button code looks like this

$.fn.dataTable.ext.buttons.filterSponsor = {
                extend:'collection',
                text: 'By Sponsor',
                fade: true,
                autoClose:true,
                buttons: [                    
                    {
                        name: '0',
                        text: 'All Sponsors',
                        data: 0,
                        action: function (e, dt, node, config) {
                            if (config.data>0) {
                                dt.buttons(0, 1).text('By Sponsor <i class="fa fa-filter"></i>');
                            } else {
                                dt.buttons(0, 1).text('By Sponsor');
                            }
                            var field = $('#FilterSponsorID');
                            sponsorFunc(config.data, field);
                            this.draw(true);
                        }
                    },                 
                     {
                        name: '12',
                        text: 'Blow, Joe',
                        data: 12,
                        action: function (e, dt, node, config) {
                            if (config.data>0) {
                                dt.buttons(0, 1).text('By Sponsor <i class="fa fa-filter"></i>');
                            } else {
                                dt.buttons(0, 1).text('By Sponsor');
                            }
                            var field = $('#FilterSponsorID');
                            sponsorFunc(config.data, field);
                            this.draw(true);
                        }
                    },

Somehow I need to trigger a redraw of the button to recreate line #28 of the example.

Answers

  • jstemperjstemper Posts: 15Questions: 10Answers: 0

    Resolved it by on page load checking the local storage to see what filter is applied and then calling

     $('#indexTable').DataTable().button(0,1).text('By Sponsor <i class="fa fa-filter"></i>');
    

    When appropriate.

Sign In or Register to comment.