Forum

November 2nd, 2014
A A A
Avatar

Lost password?
Advanced Search

— Forum Scope —




— Match —





— Forum Options —





Minimum search word length is 3 characters - maximum search word length is 84 characters

The forums are currently locked and only available for read only access
sp_Feed Topic RSS sp_TopicIcon
Displaying custom row content
11/03/2009
10:08
Avatar
thomaslundstrom
Member
Members
Forum Posts: 4
Member Since:
11/03/2009
sp_UserOfflineSmall Offline

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.

12/03/2009
11:45
Avatar
tony
Sofia, Bulgaria
Moderator
Members

Moderators
Forum Posts: 7721
Member Since:
30/10/2007
sp_UserOfflineSmall Offline

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.

13/03/2009
06:56
Avatar
thomaslundstrom
Member
Members
Forum Posts: 4
Member Since:
11/03/2009
sp_UserOfflineSmall Offline

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?

13/03/2009
10:26
Avatar
tony
Sofia, Bulgaria
Moderator
Members

Moderators
Forum Posts: 7721
Member Since:
30/10/2007
sp_UserOfflineSmall Offline

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.

13/03/2009
11:57
Avatar
thomaslundstrom
Member
Members
Forum Posts: 4
Member Since:
11/03/2009
sp_UserOfflineSmall Offline

Hi, I got it working by hiding all the data columns and then hooking onto the loadComplete event instead of a custom formatter, creating the UI there.

31/03/2009
06:52
Avatar
tacman1123
Member
Members
Forum Posts: 7
Member Since:
18/03/2009
sp_UserOfflineSmall Offline

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

01/04/2009
02:56
Avatar
tony
Sofia, Bulgaria
Moderator
Members

Moderators
Forum Posts: 7721
Member Since:
30/10/2007
sp_UserOfflineSmall Offline

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.

01/04/2009
06:19
Avatar
tacman1123
Member
Members
Forum Posts: 7
Member Since:
18/03/2009
sp_UserOfflineSmall Offline

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

02/04/2009
10:36
Avatar
tony
Sofia, Bulgaria
Moderator
Members

Moderators
Forum Posts: 7721
Member Since:
30/10/2007
sp_UserOfflineSmall Offline

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.

02/04/2009
10:45
Avatar
tacman1123
Member
Members
Forum Posts: 7
Member Since:
18/03/2009
sp_UserOfflineSmall Offline

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 

Forum Timezone: Europe/Sofia

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.com

Moderators: tony: 7721, Rumen[Trirand]: 81

Administrators: admin: 66

Comments are closed.
Privacy Policy   Terms and Conditions   Contact Information