Forum


10:08

11/03/2009

Hi, I am thinking of implementing a search browser using JqGrid. The reason why I would like to choose JqGrid is that we use it in other places of our product and I like the way I can use it to implement paging etc.
I'd like to be able to format the search results somewhat like Google formats its search results, i.e. in a list.
How would I do this using JqGrid? I've noticed that I can use a grid with one visible column and create HTML on the server side. The HTML is then displayed as each cell's content, and everything looks fine. Creating markup and sending it over JSON is however a quite ugly solution.
I would like to be able to transmit a row of data to JqGrid, and extract the data in a formatter function, and then format the data on the client side, preferably with the plugin jTemplates. Is it possible to get hold of the entire row's data in a cell formatter? If I could do that, I could create the custom HTML on the client side instead.
11:45

Moderators
30/10/2007

Hello,
Using a custom formatter I think will do the job. Maybe you will need to ajust the cell displaying using the setCell method. Refer to docs.
Regards
Tony
For professional UI suites for Java Script and PHP visit us at our commercial products site - guriddo.net - by the very same guys that created jqGrid.
06:56

11/03/2009

Hi,
I tried using a custom formatter, but didn't get it working like I wanted. My approach was:
1. Have a grid with 5 different columns, but only the first column is shown. The other columns are used to transport the data that should be visible in the first column
2. The first column has a custom formatter
3. In the custom formatter, I tried to get data from the other columns, in order to build the custom html, but I couldn't find the data in any property of the formatter parameters
Is it possible to get data from other columns when doing custom formatting for one column?
10:26

Moderators
30/10/2007

Hello,
Maybe a good solution here is to use afterInsertRow (where all the row data is available) and setCell method to set the first column data depending on others.
Regards
Tony
For professional UI suites for Java Script and PHP visit us at our commercial products site - guriddo.net - by the very same guys that created jqGrid.
06:52

18/03/2009

I'm having a similar issue, and would like to solve it using formatter. Let's say I have 4 columns, addr, city, state, zip. I want to display an address block in the custom formatter that looks like addr<br />city, state zip. I create a column called address_block and set the formatter to format_address_block
My custom format function declaration is
format_address_block = function(el, cellval, opts){...
in theory, opts returns rowData, but this is not the raw data that I'd like to see from the json data that's sent to populate the table, but rather the tr element and all the formatting. So from here, I don't know how to fill the cell based on data from other cells in the same row.
Is it possible to also pass the actual data from the row to my custom formatter?Then it would be relatively easy to solve. Maybe a 3.5 addition?
I realize there are other solutions -- formatting the data in the json requst (not really a good plan), or using setCell in afterRowInsert, but both of these add complications that I'd rather have formatter deal with.
A related question: once I have this address block, I'll obviously want to hide the individual fields during the grid display, and show the address block, but the reverse will be true when I edit. That doesn't seem to be working, if I have in the colModel "hidden":true and also "editable":true, the field still doesn't show up in the edit.
Thanks! I've been staring at this now for a while, I'd love some pointers toward a solution.
Tac
02:56

Moderators
30/10/2007

Hello,
Thanks for this. I was thinking about this for some time and will say - Yes it is possible with some limitations. I will pass to the formatter the entry row in format which is obtained from the server - with other words if you have data in format
[
...
{"id":5, cell:["cell11", "cell12", "cell13"] },
...
]
Again with the cell value you will have a array of ["cell11", "cell12", "cell13"]
What do you think will this do the job?
Regards
Tony
For professional UI suites for Java Script and PHP visit us at our commercial products site - guriddo.net - by the very same guys that created jqGrid.
06:19

18/03/2009

Yes, that would be terrific. Even better would be named pairs, e.g.
[
{"id":5, cell:{first:"Fred", last:"Flintstone", city:"Bedrock"} },
]
I know the data can be passed in that way, but I usually pass it in as an array, because the data is so much smaller that way. Or if you could show how to get the id from a name, I know there's a method that gets the column index from a name, but I couldn't figure out how to call it from within the formatter.
At the moment, we've rewritten things to use afterRowInsert, but I think that's more complicated. A colleague and I spent most of the day working on this yesterday, he found a issue related to this:
--
I discovered why the rowdata argument is always empty for afterInsertRow. There's a variable rd in grid.base.js that's initialized to [] and then later it tries to put data into it like this:
rd[ts.p.colModel[j+gi+si].name] = cur[j];
That is, it's initialized as an empty array and then treated as an object (with name rather than numeric indexes). Apparently in that situation JavaScript [appears to ignores the assignment, and rd acts an empty array].
It should be initialized to {}, an empty object, in which case everything works fine. I should be able to simplify that afterInsertRow code now.
FOLLOW-UP:
Hmm, actually it looks like the data does go in, but it doesn't show up when iterating through the array. You have to know what the keys are and specifically ask for the elements. So the data isn't lost, just hard to find.
The bottom line remains to be careful not to use non-numeric keys in a JS array. They don't get magically converted to numbers, but the resulting array doesn't act quite like an object/hash either.
---
Tac
10:36

Moderators
30/10/2007

Hello,
Check the new 3.5 Alfa 2. I have added additional parameter to the custom formatter which holds the entry row from the server adain with the id.
Regards
and Thanks for the fix
Tony
For professional UI suites for Java Script and PHP visit us at our commercial products site - guriddo.net - by the very same guys that created jqGrid.
10:45

18/03/2009

Thanks, where is the link to download that?
You have this awesome jQuery plugin, but sometimes I get lost trying to find important things (demos, documentation, alpha download, this forum, etc.) Would you consider getting jqgrid.org and posting links to everything from there? Ev
Thanks for integrating that, can't wait to try it. How would you describe the stability for the 3.5 alpha 2 -- is it new functionality mostly that needs to be tested, or were there changes that affect the current API?
Thanks again, Tony. We're moving our internal database maintence system to jQuery, and your grid is at the core our UI now, so we're grateful for making this tool available.
Tac
Most Users Ever Online: 715
Currently Online:
63 Guest(s)
Currently Browsing this Page:
1 Guest(s)
Top Posters:
OlegK: 1255
markw65: 179
kobruleht: 144
phicarre: 132
YamilBracho: 124
Renso: 118
Member Stats:
Guest Posters: 447
Members: 11373
Moderators: 2
Admins: 1
Forum Stats:
Groups: 1
Forums: 8
Topics: 10592
Posts: 31289
Newest Members:
, razia, Prankie, psky, praveen neelam, greg.valainis@pa-tech.comModerators: tony: 7721, Rumen[Trirand]: 81
Administrators: admin: 66