Kumara
Kumara

Reputation: 528

angular js data table pass row data into fucntion

I am using angular js data table to my project. currently i am trying to pass value to my onclick function . Please check my below code

$scope.loadRequestApproval = function () {

        $scope.dtOptions = DTOptionsBuilder.newOptions()
            .withOption('ajax', {
                dataType: 'json',
                contentType: "application/json; charset=utf-8",
                url: appConfig.apiUrl + "/finalizedAllList?reqTraceId=" + $scope.requestApprovalId,
                xhrFields: { withCredentials: true },
                type: 'POST',
                data: function (d) {
                    return JSON.stringify(d);

                },
                error: function (response) {
                    ajaxErrorHandler.handle(response);
                }
            })

            .withDataProp('data')
            .withOption('processing', true)
            .withOption('serverSide', true)
            .withOption('scrollY', '400px')
            .withOption('scrollX', '100%')
            .withOption('scrollCollapse', true)

            .withOption('drawCallback', function (settings) {

            });
        $scope.dtOptions.withOption('fnRowCallback',
            function (nRow, aData, iDisplayIndex, iDisplayIndexFull) {
                $compile(nRow, aData, iDisplayIndex, iDisplayIndexFull)($scope);
            });
        $scope.dtColumns = [
            DTColumnBuilder.newColumn('treaceId.traceId').withTitle('Trace ID'),
            DTColumnBuilder.newColumn('name').withTitle('Name'),
            DTColumnBuilder.newColumn('matchRatio').withTitle('Match Strength %'),
            DTColumnBuilder.newColumn('resultId').withTitle('Action').renderWith(function (data, type, full) {
                 
                full.resultId= '500asdx';

                return '<div class="btn-group-xs">' +
                    '  <button type="button" class="btn btn-flat btn-xs btn-success" ng-click="loadDataById(' + full.resultId+ ');">' +
                    '    <i class="ion ion-eye"></i>' +
                    '  </button>' +
                    '</div>';
            }).withClass('text-center').notSortable()
        ];

    };

I am trying to pass my resultId to my loadDataById function. But its not worked.

my function is as below

   $scope.loadDataById = function (requestID) {
            console.log(requestID)
        };

I found some points regarding my issue. When i use numbers, console log is printed. but if its string, console log did not print. Ex:

full.resultId= 500;
    console log print correctly as 500

full.resultId= '500asdx';
console log did not print.

why i can not use string to do this. I think you can get the my problem. thanks

Upvotes: 0

Views: 533

Answers (1)

shivaramanaiyer
shivaramanaiyer

Reputation: 615

As discussed in the comments, the only thing missing are the inverted commas for strings in the ng-click function. Solution:

ng-click="loadDataById(\'' + full.resultId + '\');"

OR

ng-click="loadDataById(' + "'" + full.resultId + "'" + ');"

I would say go for the first one as it is cleaner

Upvotes: 1

Related Questions