ng-table icon indicating copy to clipboard operation
ng-table copied to clipboard

Can't wrap ngTable around ng-if

Open cboden opened this issue 12 years ago • 9 comments

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.

cboden avatar Mar 02 '14 17:03 cboden

I've encountered the same issue and ended up wrapping my ngTable with ng-show

yarinm avatar Mar 09 '14 12:03 yarinm

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.

cboden avatar Mar 10 '14 13:03 cboden

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 avatar May 05 '14 14:05 cboden

@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.

nimeshvaghasiya avatar Jul 22 '14 06:07 nimeshvaghasiya

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.

muzuiget avatar Jul 28 '14 03:07 muzuiget

Can ng-if be wrapped around ngTable directives now?

cboden avatar Apr 15 '15 18:04 cboden

No. Have you already have found solution for this?

iyeldinov avatar Apr 16 '15 15:04 iyeldinov

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 avatar Jul 08 '15 02:07 christianacca

@christianacca , it doesn't work. Can you please post a codepen of your try?

Ebram-Tharwat avatar May 03 '17 10:05 Ebram-Tharwat