Skip to content
This repository was archived by the owner on Feb 2, 2025. It is now read-only.

Add support for directives in the DTLoadingTemplate #529

Merged
merged 1 commit into from
Dec 4, 2015

Conversation

matthew-sycle
Copy link
Contributor

… but angular-datatables only works with raw HTML

  • pass $scope into showLoading(), which passes to DTLoadingTemplate.compileHtml(), which can then compile the HTML which can contain directives
  • DTLoadingTemplate can then be overridden, with a custom html variable that can now contain directives

… but angular-datatables only works with raw HTML

- pass $scope into showLoading(), which passes to DTLoadingTemplate.compileHtml(), which can then compile the HTML which can contain directives
- DTLoadingTemplate can then be overridden, with a custom html variable that can now contain directives
@l-lin l-lin merged commit 54b4350 into l-lin:dev Dec 4, 2015
l-lin added a commit that referenced this pull request Dec 4, 2015
@l-lin l-lin added this to the v0.5.2 milestone Dec 4, 2015
@l-lin
Copy link
Owner

l-lin commented Dec 4, 2015

Good idea! 👍

However, I changed the way to override the default loading message.
So now, instead of overriding the DTLoadingTemplate factory, you will need to initialize like this;

angular.module('showcase', ['datatables'])
.run(initDT);

function initDT(DTDefaultOptions) {
    DTDefaultOptions.setLoadingTemplate('<img src="images/loading.gif" />');
}

@Rohland
Copy link

Rohland commented Dec 17, 2015

This change seems to have broken things for me. Previously, I was setting up the template like this:

var dtLoadingTemplate = function dtLoadingTemplate() {
    var loader = [];
    loader.push('<div>');
    // .... custom loader html
    loader.push('</div>');
    return {
        html: loader.join('')
    };
};

angular.module('myapp').factory('DTLoadingTemplate', dtLoadingTemplate);

The change made now causes "compileHtml is not a function" to be thrown.

For now I've refactored my code as follows.

var dtLoadingTemplate = function dtLoadingTemplate() {
    var loader = [];
    loader.push('<div>');
    // .... custom loader html
    loader.push('</div>');

    var template = {};
    template.html = loader.join('');
    template.compileHtml = function($scope){
        return template.html;
    };

    return template;
}

angular.module('myapp').factory('DTLoadingTemplate', dtLoadingTemplate);

I'm sure others will run into this too.

Perhaps look at changing the behaviour such that the html value is returned if the compileHtml method is undefined on the object.

@l-lin
Copy link
Owner

l-lin commented Dec 17, 2015

See my previous comment. You won't have to override the service DTLoadingTemplate now. You need to set the config in a run function.

@Rohland
Copy link

Rohland commented Dec 17, 2015

Yes, I understood that from the discussion :)

The point I'm making is that the change is a breaking change for anyone who
was using the approach outlined in my post. It wouldn't take a lot to
update the code to make your change backward compatible. I hope that makes
sense.

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

Successfully merging this pull request may close these issues.

3 participants