Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free.

I'm trying to derive jquery datatable to create my custom datatable and make the columns dynamic. I can't pass the colums as an object. I'm getting a string in the directive controller.

    var columns = 
        { 
            cols: [
            {
                "mDataProp": "Name",
                "render": function (data, type, full, meta) {
                    return '<a href="#/u/d/' + full.Id + '">' + full.Name + '</a>';
                }
            },
            { "mDataProp": "prop2" }


    };
    function getColumns() {
        return columns;
    }



<my-table 
          columns='columns'
          message="my message"></my-table>



app.directive('myTable', function () {
    return {
        restrict: 'E',
        templateUrl: '/TableView.html',
        replace: false,
        controller: function ($scope) {
            // $scope.urun = 
           // $scope.arg1 = attrs.headerText;
           //
        },
        scope: {
            columns: '=columns'
        },
        link: function (scope, element, attrs) {

            var columns = attrs.columns;
            console.log(columns);

        }
    }
share|improve this question

1 Answer 1

You need to assign your variable columns to a scope property in your controller and then:

app.directive('myTable', function () {
    return {
        restrict: 'E',
        templateUrl: '/TableView.html',
        replace: false,
        controller: function ($scope) {
            // $scope.urun = 
           // $scope.arg1 = attrs.headerText;
           //
        },
        scope: {
            columns: '='
        },
        link: function (scope, element, attrs) {

            var columns = $scope.columns;
            console.log(columns);

        }
    }

More info on how scope config works: $compile

share|improve this answer
    
isn't it possible to parse that data via an attribute ? –  Kubi Jan 29 at 11:54
    
it accepts a one dimension array but not 2 –  Kubi Jan 29 at 11:54
    
You can write the actual content in the attribute value and then do: var columns = $scope.$eval(attrs['columns']); –  Wawy Jan 29 at 12:41

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.