Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Empty result set #43

Closed
vivendi opened this issue Aug 7, 2014 · 5 comments
Closed

Empty result set #43

vivendi opened this issue Aug 7, 2014 · 5 comments
Labels

Comments

@vivendi
Copy link

vivendi commented Aug 7, 2014

How can I handle empty result sets? I'm using $resource to load my data with an Ajax call. When data is returned then it all works fine. But when I get no data, then the table keeps showing "Loading...".

I have HTML that looks like this:

<table datatable="ng" dt-options="dtOptions" class="row-border hover">
    <thead>
        <tr>
            <th>date (ISO)</th>
            <th>name</th>
            <th>email</th>
            <th>Actions</th>
        </tr>
    </thead>
    <tbody>
        <tr dt-rows="" ng-repeat="user in users">
            <td>{{ user.date }}</td>
            <td>{{ user.name }}</td>
            <td>{{ user.email }}</td>
            <td>actions</td>
        </tr>
    </tbody>
</table>

In my controller I have this:

// Init empty var
$scope.users = [];
//$scope.users = {}; Doesn't work either

I want to somehow init the table with an empty variable. But when I use a variable like that then it keeps saying "Loading...".

Is there a way to solve this problem?

@l-lin
Copy link
Owner

l-lin commented Aug 7, 2014

Good catch 👍 It's a bug I didn't consider.
I'm on it.

@l-lin
Copy link
Owner

l-lin commented Aug 8, 2014

Mmh I can't really find a solution within the module.
But, you can solve this by adding the ng-if directive, for example like this:

<table datatable="ng" dt-options="dtOptions" class="row-border hover" ng-if="users.length > 0">
    <thead>
        <tr>
            <th>date (ISO)</th>
            <th>name</th>
            <th>email</th>
            <th>Actions</th>
        </tr>
    </thead>
    <tbody>
        <tr dt-rows="" ng-repeat="user in users">
            <td>{{ user.date }}</td>
            <td>{{ user.name }}</td>
            <td>{{ user.email }}</td>
            <td>actions</td>
        </tr>
    </tbody>
</table>
<p ng-show="users.length == 0">No result</p>

@l-lin l-lin closed this as completed Aug 8, 2014
@vivendi
Copy link
Author

vivendi commented Aug 8, 2014

Yeah, that's what I'm doing now (the ng-if stuff). But I'd rather show the table with no rows. So the user can still see the table headers. Seems more user friendly to me.

But for now I'll stick with the ng-if solution.

@l-lin
Copy link
Owner

l-lin commented Aug 22, 2014

Code works if we give the array directly to the scope, but not working when fetching the data from promises 😢

@l-lin
Copy link
Owner

l-lin commented Aug 23, 2014

Fixed at last! 😄

@l-lin l-lin closed this as completed Aug 23, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants