How do I make the data different in every every row of the jqrid subgrid?
Asked Answered
L

1

0

I have a jqgrid with a subgrid that has one row. Right now every subgrid row has the same data what I want to know is what is the best way to populate different data in each of the subgrid rows using the subGridRowExpanded object. Here is the jsfiddle for to look at what I have done thus far:

http://jsfiddle.net/mojarame/h54Gs/light/
http://jsfiddle.net/mojarame/h54Gs/embedded/result/

Loach answered 1/6, 2012 at 18:57 Comment(3)
Check this jsfiddle.net/joycse06/h54Gs/1/embedded/result . check each subgrid and you will see Dynamic data in red at the top, fetched from an array.Galimatias
@MojaRu: Sorry, but you have to explain more clear what you need. Do you have problem to generate unique data?Cinerama
I am writing the code now. Give me a minute and I will post it in a js fiddleLoach
C
1

I am not sure that I full understand what you want, but in any way I would change your code to the following demo.

Cinerama answered 1/6, 2012 at 22:39 Comment(7)
Here is what I am trying to accomplish. I want to know is this the best way to accomplish it. I have different messages in every subgrid row. jsfiddle.net/mojarame/p38Ya thanksLoach
@MojaRa: You posted one version of the code after another one without the description what you really want. You wrote about "different data" or "different messages" without to clear the nature (the source) of the messages. Do you have an object (or an array) which could get you "the message" by the rowid or you need to get the data from the server per new Ajax request? What is your case. In your last example you includes code '<a href=\"#\" id=\"A7\" class=\"viewMore messageReply\">View Details</a>' where you have different id values. Which sense it has?Cinerama
@MojaRa: If you need to bind click on the individual <a> you can do this directly without any id. If you start to include id attribute you have to do this very carefully, because the value of ids must be unique on the page. Moreover you continue to use addRowData to fill the grid instead of direct usage of data option of jqGrid (compare your code with my). addRowData is the slowest way to fill the grid. you should better never use it. I see also no sense to set ondblClickRow after the grid is created. I find also practical to use height: "auto" with subgrids.Cinerama
I apologize Oleg here is my latest jsfiddle jsfiddle.net/mojarame/bZj59 What I was trying to demonstrate before I go into production was different messages in the different subgrid rows. I was just asking sense this is just static data for now is using the if/else conditional statments the best way to diplsay the static data?Loach
@MojaRa: It's difficult to answer "what is the best". I would define an object like var msg = {"1": "html message for subgrid with id=1", "2": "html message for subgrid with id=2", ...}; or as array var msg = ["html message for subgrid with id=1", "html message for subgrid with id=2", ...];. Inside of subGridRowExpanded you can just use var message = msg[row_id]; if (message) {$("#" + subgrid_id).append(html);}. Alternatively you can define function instead of object or array. If all the messages will be constructed from the same blocks you can use message prototype having {0}...Cinerama
@MojaRa: For example jqGrid uses internally format function. Look at the line which use $.jgrid.format(ts.p.recordtext,from,to,tot). The value of ts.precordtext are language specific and are defined in grid.locale-en.js as "View {0} - {1} of {2}" the placeholder {0}, {1} and {2} will be replaced to the values of variables from,to,tot from the call.Cinerama
@MojaRa: Probably you can use the same technique to reduce the code and generate individual messages based on message templates.Cinerama

© 2022 - 2024 — McMap. All rights reserved.