Using jqGrid's emptyrecords option
Asked Answered
O

2

4

So I have this grid. It's a very nice grid. Lovely, really. Except when I have nothing to populate it with. In that case, I'd really like to display a message indicating that, "No URLs have been loaded for evaluation.", but either I'm missing something critical or the emptyrecords option isn't behaving the way I'd expect. Can someone point me in the right direction?

var pages = <?php echo $json_encoded_array ?>;

$('#oversight-sample').jqGrid({
  altRows:   true,
  autowidth: true,
  caption:   'Evaluated URLs',
  colNames:  ['Actions', 'URL', 'Fetch Date'],
  colModel:  [
    { align: 'center', name: 'actions', index: 'actions', title: false, width: 60, resizable: false, sortable: false },
    { name: 'url', index: 'url', width: 400 },
    { align: 'center', name: 'created', index: 'created', width: 125, sorttype: 'date' }
  ],
  data:         pages,
  datatype:     'local',
  emptyrecords: 'No URLs have been loaded for evaluation.',
  forceFit:     true,
  height:       'auto',
  hoverrows:    true,
  sortname:     'created',
  pager:        '#url-pager',
  viewrecords:  true
});

If records do exist, then everything looks about like I'd expect it to look. Is there something else I need to do to get the emptyrecords message to display when there are none?

I'm using jqGrid 3.8.

Thanks.

Orelie answered 8/11, 2010 at 18:4 Comment(0)
K
4

You should verify how are the value of data parameter (the value of pages in your case). I suppose the value is null or {} instead of [].

UPDATED: You can also consider to set current page from 1 to 0 how it shows the small demo.

UPDATED 2: Of cause you can place the text about empty rows on the place of the table. In the case you have to remove height: 'auto' to be able to see the text. Look at another demo which show this.

Kolomna answered 8/11, 2010 at 20:17 Comment(6)
Hmmm. Good point. I'll ensure that I'm capturing an empty array. I imagine that you're right and the value is an empty string or null.Orelie
Neither of those seem to work the way they do in your example. Does the emptyrecords message always appear in the lower right of the pager panel? If so, that's not what I'm after so the question may be moot. I'd really like the message to display between the header and the footer of the table.Orelie
@Rob Wilkerson: What do you mean under "Neither of those seem to work the way they do in your example"? Do you can't reproduce my example in your environment? I created for you a simple demo which show how to display the message between the header and the footer of the table (see UPDATED 2 part of my answer).Kolomna
@Oleg: grid.hide() used in this demos breaks inline add. Inline add adds new row but since grid is hidden, added row is not displayed. How to fix this so that inline added row is visible ? I fixed this by adding $(t).show() to jqGrid addRowData method. Is this best fix?Leastwise
@Andrus: It seems you can create div emptyMsgDiv as div with relative or absolute position and place it over the grid body with large enough "z-Index". In the case you will don't need to use any .hide() or .show() methods on the grid. In any way if you show the div explicitly you have to hide it also explicitly. You can do this before call of addRowData or inside of some callback. You can use now new events. For example in jqGridAfterInsertRow event you can test p.reccount === 0 and show or hide the emptyMsgDiv.Kolomna
@Oleg: I used $grid.jqGrid('inlineNav', '#grid_toppager', { addParams: { addRowParams: { oneditfunc : function () { $grid.show();}}}}); to fix the issue.Leastwise
G
3

If anyone here has an issue with the JQGrid not showing the message "No Records To View", ensure that you have set the viewrecords: true option.

emptyrecords - Display the information when the returned (or the current) number of records is zero. This option is valid only if viewrecords option is set to true.

Groggery answered 2/8, 2012 at 15:0 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.