3

I am trying to generate a grid using jqgrid on a html table. I am able to do that, but I want to display a message if no rows are found in the table. How can I do that?

Here is my jquery code...

jQuery.extend(jQuery.jgrid.defaults, {
                caption: "my list",
                autowidth: true,
                height: "100%",
                hidegrid: false,
                loadComplete: function() {
                    alert("Grid has been loaded");
                },
                colModel:[
                   { name: 'date', index: 'date', width: 0, resizable: false },
                   { name: 'icon', index: 'icon', width: 0, resizable: false },
                   { name: 'shop', index: 'shop', width: 0, resizable: false },
                   { name: 'delete', index: 'delete', width: 0, resizable: false }
                ]
            });
            tableToGrid("#item_table", {
               colNames: ['Date', '', 'Shop', 'Delete']
            });
vikmalhotra
  • 9,981
  • 20
  • 97
  • 137

2 Answers2

6

The standard message defined in $.jgrid.defaults.emptyrecords (see grid.locale-en.js) will be displayed per default only in case of filling jqGrid with remote data loaded from the server (see this answer). The corresponding text (see grid.locale-en.js) "No records to view" will be displayed on the right side of the status bar.

In another answer I shown how to force displaying of the text in case of 'local' filled jqGrid (like in your case) or how to display the corresponding text in the body area of the grid (see demos from the answer). So you can do the same in case of converting existing table to jqGrid with respect of tableToGrid. The event handler beforeRequest doing this can be define either in the jQuery.jgrid.defaults or as an additional property of the second parameter of tableToGrid function. If you follows the second demo, you should modify the code of loadComplete function which you currently use to show/hide the div with the "no rows" message in the jqGrid body.

Community
  • 1
  • 1
Oleg
  • 220,925
  • 34
  • 403
  • 798
  • The link in 'another answer' is incorrect: it is the same as 'this answer' link. Where to find referenced answer and code which shows no recods found message in grid body? – Andrus Jan 29 '12 at 14:05
  • @Andrus: Thanks! I updated the link to [the answer](http://stackoverflow.com/a/4127666/315935) with to demos. – Oleg Jan 29 '12 at 14:13
0

In fact it's not a bug. If you look into jqGrid.css file you find that to each row in table is applied style with "white-space:pre"

.ui-jqgrid tr.jqgrow td {font-weight: normal; overflow: hidden; white-space:pre; height: 22px;padding: 0 2px 0 2px;border-bottom-width: 1px; border-bottom-color: inherit; border-bottom-style: solid;}

If you remove this style (from all classes in /* body */ section) then you'll want be forced to put cell content in one line with tag.