0

I have a datatable being generated by JSON array coming from a specific url. I also have a hypderlink on each column that redirects me to the next page either.

Now all I have to do is to call another function from inside the same angularjs controller.

Code for DataTable, with hyperlink columns, PLEASE REFER TO THE if BLOCK for concerned citation:

            $.getJSON('http://blahblahblah/company/all', function(data) {

            var companyId = null;
            $('#companies').DataTable({
                "aaData": data,
                "aoColumns": [
                    {"mDataProp":"companyId", "render": function(data, type, row, meta) {
                        if( type==='display' ) {
                            companyId = data;
                            data = '<a href="' + "/pages/company?companyId=" +companyId+ '">' + data + '</a>';
                            // call a function from this file when click on the above generated link, JUST HERE
                        }
                        return data;
                    }},
                    {"mDataProp":"legalName", "render": function(data, type, row, meta) {
                        if( type==='display' ) {
                            data = '<a href="' + "/pages/company?companyId=" +companyId+ '">' + data + '</a>';
                            // call a function from this file when click on the above generated link, JUST HERE
                        }
                        return data;
                    }}

                ]
            });

        });

Code for a function defined in the same controller:

        $scope.findCompanyById = function() {

        $http.get(
                'http://blahblahblah/company/find?id='
                        + $location.search().companyId).

        then(function(response) {
            $scope.company.companyInfo = response.data;
        });


    };

I am waiting for your kind response, Thanks.

6
  • Please read: stackoverflow.com/questions/14994391/… don't do any DOM manipulation in the controllers, ideally keep your controllers slim, DOM manipulation and behavior extension should be done with directives. Search for datatables directive I'm sure one exists, there may be better alternatives with the same functionality written in angular without jquery/datatables being needed. Commented Jan 5, 2018 at 6:09
  • stackoverflow.com/a/41683531/5621827 this may help Commented Jan 5, 2018 at 6:12
  • You should use the directives for jQuery DataTables -> l-lin.github.io/angular-datatables/archives/#!/welcome the other will in the long term simply not work ... Commented Jan 5, 2018 at 13:19
  • @davidkonrad could you please point to the particular directive to be used? Commented Jan 7, 2018 at 8:13
  • @BadshahTracker, open the url in a browser and click on the link "Getting started" you see at the very top to the left ... Commented Jan 7, 2018 at 10:43

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.