angular-datatables icon indicating copy to clipboard operation
angular-datatables copied to clipboard

ng-click inside DTColumnBuilder.renderwith() error

Open srikarshastry opened this issue 11 years ago • 4 comments

Hello, I'm new to this angular-datatables and I'm using the promises to get the data for table. One of the requirements is to get the column clickable with anchor tag. Now the example JSON used in the documentation uses and array of objects but i'm getting a flat array of strings. Hence, when I try:

DTColumnBuilder.newColumn(null).withTitle('Name').renderWith(function(data,type,full) {
var rr = ' <a ng-click="showName(' + data + ');"> '+data + '</a>';
return rr;
}),

I get this error: Lexer Error: Unexpected at column{1} in expression [{2}].

Any idea how to solve this?

The dtOptions I have looks like this:

$scope.dtOptions = DTOptionsBuilder.newOptions()
                    .withOption('aaData', $scope.tableArray)
                    .withOption('createdRow', function(row) {
                        // Recompiling so we can bind Angular directive to the DT
                        $compile(angular.element(row).contents())($scope);
                    })
                    .withDOM('t')
                    .withScroller()
                    .withOption('deferRender', true)
                    // Do not forget to add the scorllY option!!!
                    .withOption('scrollY', '182');

srikarshastry avatar Feb 17 '15 21:02 srikarshastry

You did not used fromFnPromise. Also, if your data contains an array of object, then data in the function renderWith is an object.

l-lin avatar Feb 17 '15 22:02 l-lin

as I mentioned in my issue, I have to construct flat list of array of strings (not array of objects). Therefore, the promise return to use in fromFnPromise is not useful for me since I have to construct a temp array first then render the table. Any idea whats missing?

srikarshastry avatar Feb 17 '15 22:02 srikarshastry

If it's a list of array of strings, then you need to use columnDefs not columns. See plnkr for example.

l-lin avatar Feb 17 '15 22:02 l-lin

Thank you so much sir. It worked smooth.

I was missing slashes () in the ng-click ng-click="showCase.showName('' + data + '');"

is there any way to document this ng-click in the documentation? I know people can access the solution here but feel like it would be better if its part of documentation (same goes for an example with flat array of strings).

Thanks alot for your hard work.

srikarshastry avatar Feb 17 '15 23:02 srikarshastry