Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

renderWith with data object in ng-click #145

Closed
Chris-c-09 opened this issue Dec 9, 2014 · 9 comments
Closed

renderWith with data object in ng-click #145

Chris-c-09 opened this issue Dec 9, 2014 · 9 comments

Comments

@Chris-c-09
Copy link

Hello,
I want to use with renderWith ng-click on a function. I followed your example. It works.
However, I need to spend all my data object in my function, because is a restangular object. Only I have this error:
Syntax Error: Token 'Object' is at column {2} of the term [{3}] starting at [{4}].

My code :

button class=btn btn-warning ng-click=selectItem(data)>

Thank you in advance for your info.

Kristi

@l-lin
Copy link
Owner

l-lin commented Dec 9, 2014

If you look at the result DOM (with your browser inspector), you should see something like selectItem([Object Object]).
What you must put in your ng-click parameter must be either a value (integer, string or boolean) or a variable that is defined in your $scope. In your code, the data is not defined in your $scope but in the renderWith function, thus throwing this error.

So, put directly your wanted data in the parameter instead of the entire data object. For example:

.renderWith(function(data) {
     return '<button ng-click="selectItem(' + data.id + ', ' + data.firstName + ')">' +
                    'Select item' +
               '</button>';
});

@l-lin l-lin added the question label Dec 9, 2014
@Chris-c-09
Copy link
Author

Thank for response
My data object has sub object and has restangular function I need.
I can not sent my data like this.

@Chris-c-09
Copy link
Author

hello,
Finally, at the time of restangular call, I put the result in a $scope. Then in renderWith, I pass the id in my office and in my job I do a pour on the scope. It works.

Kristi

@Abhi-joshi
Copy link

But how to define data in the $scope variable.. I'm unable to pass data as an object in ng-click.
I'm using server side pagination

@l-lin
Copy link
Owner

l-lin commented Jul 24, 2015

You can't right now. Related to #299.

@Abhi-joshi
Copy link

Okay I managed it somehow... now the next thing is like i have two api calls for fetching data and show in datatable...
1.No custom data(running successfully now)---->on page refresh
2. With filteration(not related to column filter api) but i'm using a form instead with input fields with a filter button..
So how i again call server side url again and pass my data into it and show in datatable

@l-lin l-lin added this to the v0.5.0 milestone Sep 4, 2015
@l-lin
Copy link
Owner

l-lin commented Sep 4, 2015

Ok, I managed somehow to pass an object in the renderWith function.
The idea is to add the object in the $scope of the controller.

In my example, I set a temp variable vm.persons that I set to an empty object, and for each call in actionsHtml, I set the vm.persons (which acts like a map) so that my functions knows what object I'm dealing with.

vm.persons = {};
...
function edit(person) {
    ...
}
function delete(person) {
    ...
}
function createdRow(row, data, dataIndex) {
    // Recompiling so we can bind Angular directive to the DT
    $compile(angular.element(row).contents())($scope);
}
function actionsHtml(data, type, full, meta) {
    vm.persons[data.id] = data;
    return '<button class="btn btn-warning"' +
        '           ng-click="showCase.edit(showCase.persons[' + data.id + '])">' +
        '   <i class="fa fa-edit"></i>' +
        '</button>&nbsp;' +
        '<button class="btn btn-danger"' +
    '            ng-click="showCase.delete(showCase.persons[' + data.id + '])")">' +
        '   <i class="fa fa-trash-o"></i>' +
        '</button>';
}

@vinays84
Copy link

vinays84 commented Jun 6, 2016

I'm currently changing datatables built with angular html code to use server-side processing and this was very helpful. I would suggest including the Binding Angular directive to the DataTable link on the Server side processing page.

@mal90
Copy link

mal90 commented Jan 31, 2017

New link for bind Angular Directive to the DataTable

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants