ParamQuery grid support forum
General Category => Help for ParamQuery Grid (free version) => Topic started by: benni on February 14, 2014, 04:45:12 pm
-
Hi,
I'm new so maybe I'm doing something terrible wrong :=)
But the problem is that the grid shows the data from the previusly loaded data.
Flow: Selects a database, fetches data from that db's table. Generate html table. The table shows the right data, but the converted grid is wrong.
Please se code below. The load fetches a generated table.
$("#databases").dblclick(function() {
var input = $("#databases").val();;
if(input != db)
db = $("#databases").val();
else
return;
var dbstring = 'fieldmappings.php?dbname=' + db;
$('#fortune').load(dbstring);
tbl = $("#fortune");
obj = $.paramquery.tableToArray(tbl);
if(newObj == null)
{
newObj = { width: 1000, height: 800, title: "ONREGFieldMappings " + db, resizable: true };
newObj.dataModel = { data: obj.data, rPP: 50, paging: "local" };
newObj.colModel = obj.colModel;
$("#grid_table").pqGrid(newObj);
$("#grid_table").pqGrid("option", "scrollModel", { horizontal: $(this).is(":checked") });
}
else {
$("#grid_table").pqGrid( "destroy" );
newObj = { width: 1000, height: 800, title: "ONREGFieldMappings " + db, resizable: true };
newObj.dataModel = { data: obj.data, rPP: 50, paging: "local" };
newObj.colModel = obj.colModel;
$("#grid_table").pqGrid(newObj);
$("#grid_table").pqGrid("option", "scrollModel", { horizontal: $(this).is(":checked") });
}
-
I couldn't reproduce your issue as I'm unable to trace global variables used in your function.
But I've created a similar fiddle for your reference.
http://jsfiddle.net/LAgZx/222/
-
UPDATE: Made it work, but not sexy, any clever guys who knows a solution? If I placed some of the code into an other click event things works, but I would be sad to have to use an extra button just for this ;=)
Se below, and more below for orig post.
$("#databases").dblclick(function() {
var input = $("#databases").val();;
if(input != db)
db = $("#databases").val();
else {
alert('returned');
return; }
alert(db);
dbstring = 'fieldmappings.php?dbname=' + db;
//alert(dbstring);
$('#fortune').load(dbstring);
});
$("#btnCheck1").click(function() {
tbl = $("#fortune");
var obj = $.paramquery.tableToArray(tbl);
var newobj = {dataModel: {data:obj.data}, colModel: obj.colModel};
if($("#grid_table").hasClass("pq-grid")){
$("#grid_table").pqGrid("destroy");
}
$("#grid_table").pqGrid(newobj);
});
Thank you, i'll tried and took a look.
The difference on the example and mine is that the old table is supposed to be replaced by a new, but I'll try.
I'v posted the full, updated, code again. Yours work the same way, the table i view is updated, but the grid is still showing the old data - always one 'refresh' behind.
Will it help to change the name of the table each time you think ?
<script>
var dbstring = 'fieldmappings.php?dbname=' + db;
//alert(dbstring);
$('#fortune').load(dbstring);
tbl = $("#fortune");
var obj = $.paramquery.tableToArray(tbl);
var newobj = {dataModel: {data:obj.data}, colModel: obj.colModel};
if($("#grid_table").hasClass("pq-grid")){
$("#grid_table").pqGrid("destroy");
}
$("#grid_table").pqGrid(newobj);
</script>
-
It's one table behind because you invoke load method which makes async server request while code execution proceeds further and loads prev table in the grid.
You need to use $.ajax method and create grid in success callback of ajax method, I hope you get the idea of what you are doing wrong.
https://api.jquery.com/jQuery.ajax/
-
Thank you very much, works like a beuty :)
;)