Forum


22:35

18/12/2008

Hello
I am currently migrating my js based dynamic column code to use the newly implemented jqGridImport as in 3.4.
Is it possible to pass or attach an event handler? I have some code I want to execute after the grid is complete so thought to use the following:
loadComplete : function()
{
// resize table width and other tidy actions
}
The problem is if I pass this as a string in JSON then it does not get evaluated as code..
Is it possible to use events using jqGridImport?
Cheers
Dave
05:12

Moderators
30/10/2007

Hello,
I think you should experiment in reverse order.
1. Construct your grid standart way including events
2. Make export of the grid using the method jqGridExport using the options jsonstring.
This way you can see how to configure the events in the jsonstring.
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.
11:48

18/12/2008

Hey Tony,
Thanks for your reply.. I had the same thought after posting on here.. and the jsonstring is displayed as I thought..
“loadComplete” : function () { ///blahblah; }, (notice the lack of quotes around the function).
The problem I am having is recreating that in PHP..
This doesnt work
$output->grid->url = “dyntab.php?action=data”;
$output->grid->loadComplete = “function() { \\\\\\ blahblah; }”;
And this wont compile in PHP (obviously.)
$output->grid->url = “dyntab.php?action=data”;
$output->grid->loadComplete = function() { \\\\\\ blahblah; };
Im not sure if there is a way to store a function in an object to be then encoded in JSON.?
The main reason I need this to happen is because I would like to fix the bug where if you add columns dynamically the total grid width grows by 7px for each column rather than keeping the width as specified in the configuration. Maybe there is another way then callng setGridWidth after creation?
Thanks
Dave
01:09

Moderators
30/10/2007

Hello,
I think this is reasonable. The grid eval the string and there is no other way to determine if this is a function. If it is a quted it is interpreted as string. Any idea on how to resolve this will be helpful. Also it is easy when we use xml - in this case the function is enloased in CDATA.
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.
08:00

18/12/2008

Tony,
Good call on the [CDATA] tags - I did some research for a PHP/JSON equivalent and the awnser, it seems, is PHP 5.3 and NOWDOC.
$complete_function = <<<'EOT'
function() { dosomething(); }
EOT;
$export->grid->gridComplete = $complete_function;
Unfortunatley no 5.3 is still in Beta and not suitable for my production server. So I have a grid workaround.
I edited grid.import.js and made your $.ajax() call non async - this way I can then use .setGridWidth to correct the grid dimensions.
Thanks for your help Tony - I will take a copy of PHP 5.3 Beta down later and test the above to enure that it works.
Dave
12:42

02/02/2009

Well, you always have an option to write your own json writer, which will build json string with your rules. When you look at english online manual, in comments to function json_encode, there are already some nice looking replacements, which you can eventualy extend for your needs. This core function is for simple types only with no extensibility.
I was solving this problem just today in my asp.net application, it was really easy.
12:54

16/04/2009

I know this topic is a bit older, but I was having the same problem with json_encode and javascript functions. After a little searching, I found this solution:
http://solutoire.com/2008/06/1.....over-json/
Very simple to implement and it works great!
--jeff
Most Users Ever Online: 715
Currently Online:
81 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