15

I want to show 'No Data Available' in ui-Grid 3.0, if the response from the ajax contains empty json data array i.e.;

data = {"data": []};

And now if i do -

$scope.gridOptions.data = data.data;

'No Data Available' must come in ui-Grid.

What is currently happening is that user gets a blank screen if data is empty.

Also how to make it as a default functionality ?

See the plunker here.

1 Answer 1

36

You could use a "watermark" (plunker) (updated plunker)

template

  <div ui-grid="gridOptions" ui-grid-selection ui-grid-exporter class="grid">
    <div class="watermark" ng-show="!gridOptions.data.length">No data available</div>
  </div>

CSS

.watermark {
    position: absolute;
    top : 80px;
    opacity: 0.25;
    font-size: 3em;
    width: 100%;
    text-align: center;
    z-index: 1000;
}

Edit:

to make the .watermark independent from the specific parent size:

.watermark {
    position: absolute;
    top: 50%;                    <---- Center vertically in the parent element,
    transform: translateY(-50%); <---- it works for any parent height
    opacity: 0.25;
    font-size: 3em;
    width: 100%;
    text-align: center;
    z-index: 1000;
}
Sign up to request clarification or add additional context in comments.

5 Comments

Thanks a lot. You saved me a lot of time!! Updated the plunker with your solution.
if I want to apply this watermark to the row data which is empty,how can i add this class at that row (box).
Man you are awesome
I used your solution, its good, but I have api calls which will take some time so this no data available will start showing while api is processing, any solution for this? to hide that msg initially?
@Sudarshan you could define a variable on the controller scope api_done and ng-show="api_done && !gridOptions.data.length"

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.