AngularJS ui-grid- To show 'No Data Available' when the response contains empty array
Asked Answered
M

1

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.

Malachy answered 24/1, 2015 at 13:21 Comment(0)
B
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;
}
Bairam answered 24/1, 2015 at 14:14 Comment(5)
Thanks a lot. You saved me a lot of time!! Updated the plunker with your solution.Malachy
if I want to apply this watermark to the row data which is empty,how can i add this class at that row (box).Jesus
Man you are awesomeFarland
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?Octastyle
@Sudarshan you could define a variable on the controller scope api_done and ng-show="api_done && !gridOptions.data.length"Bairam

© 2022 - 2024 — McMap. All rights reserved.