Forum



17:11

25/10/2008

Hello everyone!!!
I have this example at http://www.luigino.netsons.org.....inpage.php where there's a combo with elements related to different tables… this combo is actually managed with sort of xmlhttprequest you can see in this file http://www.luigino.netsons.org.....stlocal.js.
Each option I select would load an external php file which should show a jqGrid calling a function that's inside the external file (like a different jqGrid for each different external file)
The matter is while injecting contents in a DIV from external file through xmlhttprequest won't load external scripts written in that file to apply, so I found around a sort of a function like:
function loadobjs() {
if (!document.getElementById)
return;
for (i=0; i<arguments.length; i++) {
var file=arguments[i];
var fileref="";
if (loadedobjects.indexOf(file)==-1) { //Check to see if this object has not already been added to page before proceeding
if (file.indexOf(".js")!=-1) { //If object is a js file
fileref=document.createElement('script');
fileref.setAttribute("type","text/javascript");
fileref.setAttribute("src", file);
}
else if (file.indexOf(".css")!=-1) { //If object is a css file
fileref=document.createElement("link");
fileref.setAttribute("rel", "stylesheet");
fileref.setAttribute("type", "text/css");
fileref.setAttribute("href", file);
}
}
if (fileref!="") {
document.getElementsByTagName("head").item(0).appendChild(fileref);
loadedobjects+=file+" "; //Remember this object as being already added to loadedobjects+page;
}
}
}
loadobjs(), but looks like it doesn't really load scripts.
So I am thinking to change the whole loading contents and script using jQuery and I found in the documentation a $.load(….) to load contents to div and a $.getScript(…) to load scripts.
So I am here asking you how I could preload scripts (jquery-1.4.2.js, grid.locale-it.js and jquery.jqGrid.min.js) while loading (with $.load() or $.ajax() ) the external file in the <div> then applying scripts in the <div> so they could be applied once loaded the content and jqGrid would be executed? I thought about $.getScript() but how I could use it in this way in the onChange event's select?
Just so in this way I won't modify anymore the mainpage.php but just in the future adding new table and creating just a new PHP file with a new jqGrid function for that new table…
Thanks to everyone in advance!!
Ciao
Luigi
15:30

25/10/2008

found the solution: had just to put jQuery(document).ready(function(){...});
in different .js files then doing in onChange of the select a $.getScript('jsfilename.js'); et voilà but I have this little issue:
<link rel="stylesheet" type="text/css" media="screen" href="js/src/css/ui.jqgrid.css" />
<link rel="stylesheet" type="text/css" media="screen" href="js/src/css/jquery.searchFilter.css" />
<script type='text/javascript' src='grid.locale-it.js'></script>
<script type='text/javascript' src='js/src/grid.loader.js'></script>
<script type='text/javascript' src='jquery.jqGrid.min.js'></script>
<div class="wrap">
<?php
$dblink = mysql_connect('94.141.20.174', 'luiginon_luigino', 'plunzl73t23l682d') or die('Could not connect: ' . mysql_error());
$db_selected = mysql_select_db('luiginon_db', $dblink) or die ('Can\'t use luiginon_db : ' . mysql_error());
$all_tables = mysql_query("SELECT table_name, table_comment FROM `INFORMATION_SCHEMA`.`TABLES` WHERE `TABLE_SCHEMA` = 'luiginon_db' AND `TABLE_NAME` LIKE 'vvd_%' ORDER BY `TABLE_NAME`", $dblink) or die ('Query not valid' . mysql_error());
?>
<form>
<select name="selecttable" id="selecttable" onChange="$('#list').GridUnload; $.getScript(ajaxcombo('selecttable'))">
<option value="">Select a table...</option>
<?php
while ($row = mysql_fetch_assoc($all_tables)) {
?><option value="<?php echo $row['table_name']; ?>"><?php echo $row['table_comment']; ?></option><?php
}
mysql_free_result($all_tables);
?>
</select>
</form>
<div id="contentarea">
<div>
<table id="list"></table>
<div id="pager"></div>
</div>
</div>
</div>
I select different table which doesn't have a grid or even another grid with different settings, and GridUnload looks like it doesn't work to re-create the grid or leave original html blank, and maybe you could give me a trick.. any idea? thanks
Ciao,
Luigi
12:11

25/10/2008

Hi tony again...
I figured out the issue is another issue... precisely: in the documentation I saw to use GridUnload I should use grid.loader.js which contains the .js that has the function GridUnload. So I removed the <script> line about loading jquery.jqGrid.min.js since it's supposed to be already loaded by grid.loader.js....and it's supposed to create grid the function should be the same as like :
jQuery(document).ready(function(){
jQuery("#list").jqGrid({
url:'example.php',
datatype: 'xml',
mtype: 'GET',
colNames:['Inv No','Date', 'Amount','Tax','Total','Notes'],
colModel :[
{name:'invid', index:'invid', width:55},
{name:'invdate', index:'invdate', width:90},
{name:'amount', index:'amount', width:80, align:'right'},
{name:'tax', index:'tax', width:80, align:'right'},
{name:'total', index:'total', width:80, align:'right'},
{name:'note', index:'note', width:150, sortable:false}
],
pager: '#pager',
rowNum:10,
rowList:[10,20,30],
sortname: 'invid',
sortorder: 'desc',
viewrecords: true,
caption: 'My first grid'
});
});
But it doesn't appear...if I load jquery.jqGrid.min.js indeed it appears (but looks like can't unload it). Why?...I am on apache+mysql+php under windows actually before to upload on linux host... might be that cause?...
Thanks in advance and sorry for this but maybe the documentation doesn't explain about this possible differences...or yes?...
Ciao
Luigi
15:26

25/10/2008

Nevermind… solved it by myself…actually!
Practically I did:
<script type='text/javascript' src='http://localhost/..../js/i18n/.....?ver=2.9.2'></script>
<script type='text/javascript' src='http://localhost/..../js/src/g.....?ver=2.9.2'></script>
<script type='text/javascript' src='http://localhost/..../js/jquer.....?ver=2.9.2'></script>
<—- Where in this jQuery I had
to be sure it was included whatever is necessary for use selecting in download manager page
then:
<select name="selecttable" id="selecttable"
onChange="$('#datatable').GridUnload('#datatable'); $.getScript(ajaxcombo('selecttable'))">
[...]
<div id="contentarea">
<table id="datatable"></table>
<div id="pager"></div>
</div>
in this way it doesn't need explanations…
Now I'm going to implement the code relative to manage tables and stuffs… 🙂
Thanks anyway tony and compliments for your plugin again 🙂
Be cool!
Ciao
Luigi
Most Users Ever Online: 715
Currently Online:
37 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