3

By default, when having no data, jqGrid displays the message 'No records to view' inside a pager. (My grids use the top pager).

The problem is, the message is easy to miss.

I'd like to make the grid display the message below the top header, in the same place where the rows would show up if there was any data. (in the body layer, as defined in the documentation).

Alternatively, though less desirable, I'd be fine with leaving the message where it is, but showing it in a big, fat, red font-face.

The message has css class ui-paging-info applied, but I can't just update that because the sae class is also used for displaying the message 'X records found', when the datasource is not empty, and I don't want that to be big and red :).

From what I've seen in the jqGrid source, the message is set in the function updatepager.

[...]
pgboxes = ts.p.pager || "";
pgboxes += ts.p.toppager ?  (pgboxes ? "," + ts.p.toppager : ts.p.toppager) : "";
[...]
if(pgboxes) {
    [...]
    if (ts.p.viewrecords){
        if(ts.p.reccount === 0) {
            $(".ui-paging-info",pgboxes).html(ts.p.emptyrecords);
        } 
        else [...]

I'm guessing that's where I should be injecting some custom logic, but I'm not sure how to do that.

I could just hack the jqGrid source, but I'd rather not -> that would be painful for future jqGrid upgrades.

Cristian Diaconescu
  • 34,633
  • 32
  • 143
  • 233

1 Answers1

5

I described in the old answer and this one a way how one can implement your requirements.

The demo uses the current 4.6.0 version of jqGrid and displays

enter image description here

In case of some data need be displayed the grid looks like on another demo

enter image description here

If I correctly understand your question the demos should do what you need.

Community
  • 1
  • 1
Oleg
  • 220,925
  • 34
  • 403
  • 798
  • Thanks! Now *that's* a prominent message :) I had just reached a similar solution on my own -- it's good to have it validated. Also, interesting alternatives in the other answers you provided. – Cristian Diaconescu Jul 07 '14 at 14:23
  • How to remove this "0 records found" message and load the data back? I tried "cleargriddata" method available in jqgrid but, that does not remove this custom message... – JGV Nov 12 '15 at 17:52
  • @VimalanJayaGanesh: It would be better if you open new question and describe exactly what you need to implement. Which `datatype` you use? How you fill the grid? How you reload the data? Do you need to display the message "0 records found"? In which case exactly it should be didplayed and in which not? You should include additionally in all questions which jqGrid version you use and which fork of jqGrid ([free jqGrid](https://github.com/free-jqgrid/jqGrid), [Guriddo jqGrid JS](http://guriddo.net/?page_id=103334) or some old jqGrid in version <=4.7). – Oleg Nov 12 '15 at 18:00