question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Action Button loosing it's binding on browser resizing, Please Help

See original GitHub issue

Hi @l-lin

I followed the example from angular-datatables advance example Bind Angular Directive and used it together with the Responsive plugin. but it’s loosing action filed’s Binding.

I have follow all comments from the issue https://github.com/l-lin/angular-datatables/issues/324 but no luck,

image

it’s working fine in full screen.

image

Here is the Code:

‘use strict’; angular.module(‘showcase.withResponsive’, [‘datatables’]) .controller(‘WithResponsiveCtrl’, WithResponsiveCtrl);

function WithResponsiveCtrl($scope, $compile,DTOptionsBuilder, DTColumnBuilder) { var edit = function() { alert(‘edit!’); };

var deleteRow = function() {
    alert('delte!');
};
var actionsHtml = function (data, type, full, meta) {
return '<button class="btn btn-warning" ng-click="edit()">' +
    '   <i class="fa fa-edit"></i>' +
    '</button>&nbsp;' +
    '<button class="btn btn-danger" ng-click="deleteRow()">' +
    '   <i class="fa fa-trash-o"></i>' +
    '</button>';
};
 var createdRow = function (row, data, dataIndex) { 
    $compile(angular.element(row).contents())($scope);
};

$scope.edit = edit;
$scope.deleteRow = deleteRow;
$scope.message = '';
$scope.dtInstance = {};


$scope.dtOptions = DTOptionsBuilder.fromSource('http://127.0.0.1:1771/data.json')
    .withPaginationType('full_numbers')
.withOption('createdRow', createdRow)
    .withOption('responsive', true);
$scope.dtColumns = [
    DTColumnBuilder.newColumn('id').withTitle('ID'),
    DTColumnBuilder.newColumn('firstName').withTitle('First name'),
    DTColumnBuilder.newColumn('lastName').withTitle('Last name'),
    DTColumnBuilder.newColumn(null).withTitle('Actions').notSortable().renderWith(actionsHtml)
];

}

Table HTML

                           <table datatable="" dt-options="dtOptions" dt-columns="dtColumns" dt-instance="dtInstance" class="row-border hover" width="100%"></table>

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:8 (1 by maintainers)

github_iconTop GitHub Comments

5reactions
marcokorbcommented, Oct 14, 2016

Hello, just to share an option to bind a directive in child rows that worked for me.

If you check the dataTables.responsive.js, Responsive object has a static object called ina property defaults with the following code:

details{
   renderer: function ( api, rowIdx, columns ) {
      var data = $.map( columns, function ( col, i ) {
            return col.hidden ?
                  '<li data-dtr-index="'+col.columnIndex+'" data-dt-row="'+col.rowIndex+'" data-dt-column="'+col.columnIndex+'">'+
                        '<span class="dtr-title">'+
                              col.title+
                        '</span> '+
                        '<span class="dtr-data">'+
                            col.data+
                        '</span>'+
                   '</li>' : 
                   '';
               }).join('');

               return data ?
                    $('<ul data-dtr-index="'+rowIdx+'"/>').append( data ) :
                    false;
           }}`

So, in the controller you must copy the code above and simply turn that into a function:

  function renderer( api, rowIdx, columns ) {
                var data = $.map( columns, function ( col, i ) {
                     return col.hidden ?
                         '<li data-dtr-index="'+col.columnIndex+'" data-dt-row="'+col.rowIndex+'" data-dt-column="'+col.columnIndex+'">'+
                              '<span class="dtr-title">'+
                                  col.title+
                            '</span> '+
                            '<span class="dtr-data">'+
                                col.data+
                           '</span>'+
                       '</li>' : 
                       '';
                   }).join('');

                   return data ?
                       $compile(angular.element($('<ul data-dtr-index="'+rowIdx+'"/>').append( data )))($scope) :  
                        false;
               }

And now we set the responsive option with our new function:

DTOptionsBuilder
     .fromFnPromise(fnPromise)
     .withOption('responsive', {
          details: {
              renderer: renderer
          }
     })
2reactions
ghostcommented, Jan 1, 2016

what about the idea of compiling the content of the child after showing it ?

something like this :

    $compile(angular.element(row).contents())($scope);
Read more comments on GitHub >

github_iconTop Results From Across the Web

Jquery - Click event doesn't work after resized - Stack Overflow
When you resize the screen you are removing the elements and re-adding them, thus losing the binding (on removal). With the $(document).on...
Read more >
Handling Events :: Eloquent JavaScript
The window binding refers to a built-in object provided by the browser. ... during resizing, as long as the button is held we...
Read more >
A Complete Guide to Links and Buttons - CSS-Tricks
Our complete guide to links, buttons, and button-like inputs in HTML, CSS, and JavaScript.
Read more >
Button UI Not Working with The new Input system - Unity Forum
I put the PlayerInput on a separate GameObject from the EventSystem and the rest, then set the binding of the mouse left and...
Read more >
EventTarget.addEventListener() - Web APIs | MDN
This creates an options object with a getter function for the passive property; the getter sets a flag, passiveSupported , to true if...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found