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.

Gyrocode.com
  • 57,606
  • 14
  • 150
  • 185
Sikandar Sahab
  • 638
  • 3
  • 10
  • 27
  • Please read: https://stackoverflow.com/questions/14994391/thinking-in-angularjs-if-i-have-a-jquery-background 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. – shaunhusain Jan 05 '18 at 06:09
  • https://stackoverflow.com/a/41683531/5621827 this may help – jitender Jan 05 '18 at 06:12
  • You should use the directives for jQuery DataTables -> **http://l-lin.github.io/angular-datatables/archives/#!/welcome** the other will in the long term simply not work ... – davidkonrad Jan 05 '18 at 13:19
  • @davidkonrad could you please point to the particular directive to be used? – Sikandar Sahab Jan 07 '18 at 08:13
  • @BadshahTracker, open the url in a browser and click on the link "Getting started" you see at the very top to the left ... – davidkonrad Jan 07 '18 at 10:43
  • @davidkonrad I couldn't really find the actual directive to use, could you please name it for me? – Sikandar Sahab Jan 09 '18 at 10:39

0 Answers0