0

In general we call the jqgrid as in$("#grid_loc").jqGrid({});
But i want to specify the context like $("#grid_loc",context).jqGrid({}).
But this is not working. Can somebody help in this?
I have to load server side data using url option.
Infact i occured to have this, as i have tabs on my page. In each tab, i have to have a jqgrid, not different grids but same grid with different data . Here i am getting the tab context using

var tabset = $("div.tabset"); newdivid = $("div[class*='active_tab']",tabset).attr("id"); var newmenudivid = $("#"+newdivid);

And the grid code as

$("#grid_workflow", newmenudivid).jqGrid({....});


I have been trying to find out a way to do this. you can find some of my effort in the comments section of the link how to develop same jqgrid in multiple tabs


i was successful with id overwriting for the same purpose. But that is not a good way though. So i am forced to have another approach ie. context

Community
  • 1
  • 1
venugopal
  • 427
  • 6
  • 13
  • @Oleg if you have time could you please help in this? – venugopal Oct 19 '12 at 06:06
  • @tpeczek Edited the question.And Please let me know if any data needed from my side and help me in this. – venugopal Oct 19 '12 at 06:55
  • And how the table elements inside of those tabs/divs looks like (you need to have actual table element to build jqGrid on it) - I don't see you adding those in your code (putting the context into selector will not make an element move into the parent object). – tpeczek Oct 19 '12 at 06:58

1 Answers1

1

I suppose that you misunderstand some important things which corresponds to id attribute. The most important that all elements on the page having id attribute have to have unique value of the attribute. In other words the ids have to be unique over the whole HTML page.

So if you need create for example tree grids inside of tree tabs you have to define different id attributes for every grid. For example; grid_workflow1, grid_workflow2, grid_workflow3. If you create the tabs and grids dynamically then you can have some variable in the outer scope (for example global variable) and increase the value of the variable. You can construct id of the grid using some prefix (like "grid_workflow") and the value of the variable. In the way you can create multiple grids with unique ids. Many JavaScript libraries uses the way to generate unique id attribute. Ij you want you can use $.jgrid.randId() method which will returns you unique strings which can be used as ids.

Because of the syntax $("#grid_workflow", newmenudivid) you should understand one important thing. I would recommend never use it. The reason is very easy. It could help only if you have id duplicates. In all other cases if will works exactly like $("#grid_workflow") but slowly. The reason is easy to understand. Web browser hold internally the list if all ids on the page and if you use getElementById method directly of indirectly (in $("#grid_workflow")) the searching of the element with the required id will be like searching in the index in the database. So you will have best performance results. If you use $("#grid_workflow", newmenudivid) then you don't allow web browser to use the index of elements by id. So the usage of context will follow to slow searching throw all children elements of newmenudivid. So you should avoid usage of jQuery context with id selectors.

Oleg
  • 220,925
  • 34
  • 403
  • 798
  • Thank you very much for explaining in such a descriptive and understandable way even for a newbie like me.And I think I owe you a beer as I started my learnings about jqgrid with your demos. Thank you once again. – venugopal Oct 19 '12 at 16:04