Hi,
In the main page there is a datagrid which uses sub-grids. This works fine.
When the user clicks on a link associated with a sub-grid entry, a new jeasyui window is spawned. In this new window I try to draw a new datagrid to display some additional data. I have found that there are two ways which nearly work.
The first datagrid follows the form laid down in the tutorials. Because the windows don't exist until the link is clicked, the form of the code to render the datagrid is only loosely based on the tutorial code.
The below code has been abbreviated for the sake of brevity, the main functional code has been broken up to highlight that the "//create datagrid" sections are interchangeable. To create a working example may require a little extrapolation from the below.
For example the virtual window is anchored to a <div id="w"></div> block in the main page. The variables taken by the addDiv() function are there as a key to the table being examined, window title etc. and not needed in a functional sense.
Calling the function is done by adding an attribute to a link of my choosing. As each link is associated with a sub-grid element it is able to be given a unique id at run time.
This code lives part of a form initialisation.
var myLink = document.getElementById("Link");
myLink.setAttribute("onclick", "javascript:addDiv(" +val1 + ", '" + val2 + "', '" + val3 + "');$('#" + val1 + "').window('open');$('#" + val1 + "').window('center')");The Window and Datagrid generation code.
function addDiv(md_id, m_title, volume){
//Check if the window has been opened before.
if (document.getElementById(md_id)!=null){
console.log("Window already exists");
} else {
//Set up HTML elements to frame window
var myDiv = document.getElementById("w");
var winDiv = document.createElement('DIV');
winDiv.setAttribute("id", md_id);
myDiv.appendChild(winDiv);
}
//Decorate window
$('#'+ md_id).window({
width:500,
height:200,
title:m_title
});
//Build the table
Buildt(md_id, volume); //create datagrid
$('#sha-view_'+md_id).datagrid({ url:"fetch_S1s.php?="+md_id });
}
//create datagrid
$('#sha-view_'+md_id).datagrid({
view: detailview,
detailFormatter:function(index,row){
return '<div id="ddv-' + index + '" style="padding:2px"><table class="ddv"></table></div>';
}
});
}
function Buildt(md, vl){
//Where to put the table
var myTableDiv = document.getElementById(md);
// Check if the table has already be created
if (document.getElementById("sha-view_" + md)!=null){
console.log("Table already exists");
} else {
//Set the table up for the datagrid
var table = document.createElement('table');
table.setAttribute("id", "sha-view_" + md);
table.setAttribute("url", "fetch_S1s.php?="+md);
table.setAttribute("class", "easyui-datagrid");
table.setAttribute("title", "SHA1 "+vl);
table.setAttribute("rownumbers", "false");
//Table structure
var tableHead = document.createElement('thead');
table.appendChild(tableHead);
//Table fields
var fid = document.createElement('th');
fid.appendChild(document.createTextNode("ID"));
fid.setAttribute("field", "file_id");
tableHead.appendChild(fid);
//Table fields
var fn = document.createElement('th');
[... createTextNode, field etc.]
tableHead.appendChild(fn);
//Table fields
var sa1 = document.createElement('th');
[... code]
tableHead.appendChild(sa1);
//Deliver Table to customer
myTableDiv.appendChild(table);
}
}All feedback is welcome!