Can't wrap ngTable around ng-if
I'm trying to conditionally have some tables depending on user input and ajax responses. I'm using dynamic columns and have an ng-table wrapped in a div with an ng-if statement.
Even if the condition is always true it breaks the ng-table.
I've encountered the same issue and ended up wrapping my ngTable with ng-show
I'm using ng-show for now but it's not ideal. ng-show hides the contents but they're still evaluated by Angular where as with ng-if will not when false.
Any info on this? I'm happy to write a PR with some direction as to what the issue is.
ng-show doesn't suite my needs; I need the code to not be evaluated because my ngTableParams variable is re-used with different tables but only one showing at a time. ng-show has weird results because ngTableParams are being evaluated twice.
@cboden i've same issue. i use ngTableParams for 5 tables. i use ng-show in all 5 tables. when it loads first time, there are http request inside ngTableParams which evaluated 5 times. and in ng-if case it automaticaly evaluate server request when the case is changed.
I have same issue, after reading the source code, I found the code which cause this bug
https://github.com/esvit/ng-table/blob/bd9ec42172389257fcd312330013302b2696ac2a/src/scripts/05-directive.js#L130
This code try add thead and pagination template automatically, but it seem to $compile will fail to parse ng-include if it inside ng-if.
So my workaround is add ng-table to class attribute, to skip this part code, and add the thead or pagination template manually.
Can ng-if be wrapped around ngTable directives now?
No. Have you already have found solution for this?
I don't think ngTableParams was ever designed to be shared across different tables. So first thing I would suggest is to maintain separate ngTableParams per html table.
I have tested wrapping a table inside of a div with an ng-if. It seems to work correctly ie the table is rendered with an ngTable directive only when the ng-if evaluates true. This is working against the latest version as I speak (https://github.com/esvit/ng-table/commit/016827745bd618aeafc16f4deaa855b29452626a = a few commits ahead of v0.5.5)
I extended demo26.html like so:
<p><label>Include table
<input type="checkbox" value="false" ng-model="includeTable"/>
</label></p>
<div ng-if="includeTable">
<table ng-table="tableParams" show-filter="true" class="table">
<tr ng-repeat="user in $data">
<td data-title="'Name'" sortable="'name'" filter="{ 'name': 'text' }">
{{user.name}}
</td>
<td data-title="'Age'" sortable="'age'" filter="{ 'age': 'text' }">
{{user.age}}
</td>
</tr>
</table>
</div>
@christianacca , it doesn't work. Can you please post a codepen of your try?