-
Notifications
You must be signed in to change notification settings - Fork 490
How to add custom button #402
Comments
You need to define your own dom. |
In javascript datatable i can done custom dom. but i m getting problem to Best Regards, On Mon, Aug 17, 2015 at 1:52 AM, Louis LIN [email protected] wrote:
|
I assume you want a custom button that can use Angular directives.
angular.module('datatablesSampleApp', ['datatables'])
.controller('SimpleCtrl', SimpleCtrl);
function SimpleCtrl(DTOptionsBuilder, DTColumnDefBuilder) {
var vm = this;
vm.dtOptions = DTOptionsBuilder.newOptions()
// Add your custom button in the DOM
.withDOM('<"custom-btn">pitrfl');
vm.dtColumnDefs = [
DTColumnDefBuilder.newColumnDef(0),
DTColumnDefBuilder.newColumnDef(1).notVisible(),
DTColumnDefBuilder.newColumnDef(2).notSortable()
];
}
angular.module('datatablesSampleApp')
.directive('customBtn', customBtn);
function customBtn() {
return {
restrict: 'C', // Notice the C for "class" restriction
template: '<h1>Foobar</h1>'
};
}
angular.module('datatablesSampleApp')
.directive('datatableWrapper', datatableWrapper);
function datatableWrapper($timeout, $compile) {
return {
restrict: 'E',
transclude: true,
template: '<ng-transclude></ng-transclude>',
link: link
};
function link(scope, element) {
// Using $timeout service as a "hack" to trigger the callback function once everything is rendered
$timeout(function () {
// Compiling so that angular knows the button has a directive
$compile(element.find('.custom-btn'))(scope);
}, 0, false);
}
}
<div ng-controller="SimpleCtrl as showCase">
<datatable-wrapper>
<table datatable dt-options="showCase.dtOptions" dt-columns="showCase.dtColumns">
</table>
</datatable-wrapper>
</div> Result on codepen. |
<title>Bootstrap 101 Template</title>
http://cdn.datatables.net/1.10.2/css/jquery.dataTables.min.css"
http://cdn.datatables.net/1.10.2/js/jquery.dataTables.min.js"></script>
as needed -->
.controller('SimpleCtrl', SimpleCtrl) function SimpleCtrl(DTOptionsBuilder, DTColumnBuilder, $resource, vm.dtOptions =DTOptionsBuilder.fromFnPromise(function() { vm.dtColumns = [ } /**
/**
This my code when i am using .fromFnPromise at the time custom button not Best Regards, On Fri, Aug 28, 2015 at 3:01 PM, Gajendrasinh Zala <
|
I am getting this error Error: [$compile:multidir] Multiple directives Best Regards, On Sun, Aug 23, 2015 at 11:06 PM, Louis LIN [email protected]
|
Can anyone please tell me how to render this customBtn inside Datatable coloum at the End ?? |
you can accomplish this using the draw.dt event. in this example i have added the attribute
pseudo code for the standard setup so may need to be modified for angular-datatables angular.module(...)
.directive('datatable', function() {
return {
template: ...,
restrict: 'AE',
...
controller: ['$scope', '$element', '$attrs', '$compile', function($scope, $element, $attrs, $compile) {
$($element).DataTable(options).on('draw.dt', function() {
$compile($($element).find('[data-compile="true"]'))($scope);
});
}]
};
}); |
I want to add my custome botton in near of Search box. how to add new button ni angular js datatable
The text was updated successfully, but these errors were encountered: