When jqGrid is empty I want to display single empty row inside the grid with information message that there are not any data. How is this possible? Thanks
相关问题
- Is there a limit to how many levels you can nest i
- How to toggle on Order in ReactJS
- void before promise syntax
- Keeping track of variable instances
- Can php detect if javascript is on or not?
The tricky bit is getting the message to show up spread across the columns. I don't think there's a simple way to do that; you'd have to, say, hide all the columns except the first one, set the first column's width to fill the grid, and put the message in the first column. Then when you reload you'd have to undo all that. It should work, but it's kind of messy.
However, let's say you just want to put the message into the first column and leave the rest empty. Basically, you implement the "loadComplete" event function and manipulate the grid's contents.
Add a property to your grid object like so:
Where "#grid_id" is the ID of your grid container, "blankRow" is an arbitrary ID you've given to the new row you've added, and "firstCol", "secondCol" and so forth are the names of the columns.
Append your error container on success as
I implemented it as follows (although this does depend on the fact I was using the provided pager functionality). All that is displayed when no records are returned is the Caption bar and one Pager bar displaying "No records to view".
Snippet of my code from setting jqGrid default options early (before grid is even loaded on my page):
Snippet of my code from loading jqGrid:
EDIT: You could also reference this answer How can I hide the jqgrid completely when no data returned? and do one of two things:
1) Put your message in one div and the grid in another. Hide the grid and show the message.
2) Put your message in a div directly below the grid. Follow my approach above, but hide all pagers (not just one). Show your div in the same event handler. All you should see is the Caption bar and your message div.
I was looking for answer to this one and came up with the following solution, but I'm not talking to the server, so I have to using something besides the 'loadComplete' event. I hooked into the 'gridComplete' event and check to see if there are any records. If not, display your empty text, otherwise hide it.
I found the best way to do this and allow the grid to handle it is to return the default parameters with no rows. For example, I'm using JSON data, so this would be the return JSON.