0

I was just wondering if this a way to display "No data available" instead of grid if json returned by the controller is empty? In the code below gridData stores the json returned by the controller

<div class="row">

    <table class="table table-striped table-hover ">
        <thead>
            <tr>
                <td><b>Format</b></td>
                <td><b>Day of Month</b></td>
                <td><b>Day of Week</b></td>
                <td></td>
            </tr>
        </thead>
        <tbody>
            <tr ng-repeat="i in gridData">
                <td>{{i.Id}}</td>
                <td>{{i.DayofMonth}}</td>
                <td>{{i.DayofWeek}}</td>
                <td><button class="btn btn-danger" ng-click="delete('{{i.Id}}')">Delete</button></td>
            </tr>
        </tbody>
    </table>
</div>

2 Answers 2

2

You can use ng-switch

<div class="row">
  <div ng-switch="gridData">
    <div ng-switch-when="gridDataIsEmpty()">No data available</div>
    <div ng-switch-when="!gridDataisEmpty()"> <!-- Normal table Code --> </div>
  </div>
</div>
Sign up to request clarification or add additional context in comments.

Comments

1

Try this:

<div class="row">

        <table class="table table-striped table-hover " ng-if="gridData.length > 0">
            <thead>
                <tr>
                    <td><b>Format</b></td>
                    <td><b>Day of Month</b></td>
                    <td><b>Day of Week</b></td>
                    <td></td>
                </tr>
            </thead>
            <tbody>
                <tr ng-repeat="i in gridData">
                    <td>{{i.Id}}</td>
                    <td>{{i.DayofMonth}}</td>
                    <td>{{i.DayofWeek}}</td>
                    <td><button class="btn btn-danger" ng-click="delete('{{i.Id}}')">Delete</button></td>
                </tr>
            </tbody>
        </table>

    <div ng-if="gridData.length === 0">No data available</div>
    </div>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.