Start Building Professional
Web Apps Today


 
Categories Question details Back To List
Question  posted by ruquia on Aug 31, 2008 06:46
open dhtmlx forum
dynamic populating DHMLXGRID

Hi,
I am unable to come out of it. I am Explaining the scenario and please help me out in this.
I have a html file in which I added the DHTMLX grid , my html file is:
<html>
<label ID=acode1>AreaCode:</label>
<input type=text id=sacode onfocus="getPlotnumbers();" READONLY>
<button type=submit ID=SEARCHAREACODE title="SEARCH AREACODE" ONCLICK='popuponclick()'>
</button>
<label ID=l1 ><FONT SIZE="2" COLOR="">Available Plots-------------------------------</FONT></label>
<DIV ID=l2 READONLY></DIV>
<label ID=l3 >Plot No</label>
<input ID=l4 type=text name=plotno>
<DIV ID=div1 >
<DIV ID=cinfo>  Customer Info</DIV><BR>
<body style="overflow:hidden" >
<DIV id="gridbox1" width="100%" height="82" ></DIV>
<script>
var mygrid = new dhtmlXGridObject('gridbox1');

// mygrid.setImagePath("codebase/imgs/");

mygrid.setHeader("serial#,Row#,SessionID,PlotNo,MunAreacode,MunPlotNo,Action,Status,ParentPlotNo,Comment,UserDefComment,NetworkLog,LastUpdatedBy,LastUpdatedDate");

mygrid.setInitWidths("60,60,80,60,100,90,50,50,90,90,120,100,100,120");

mygrid.setColAlign("right,left,left,left,left,left,left,left,left,left,left,left,left,left");

mygrid.setSkin("light");

mygrid.init();

mygrid.enableSmartRendering(true);
gridQString = "http://localhost:8080/MyPlots/GetCustomerDetails";
mygrid.loadXML(gridQString );


//mygrid.loadXML("grid_big.xml");

</script>


</DIV>

</body>
</HTML>




On clicking the button ‘SEARCHAREACODE’ a popup opens and I select an ‘areacode’ then selected areacodes plotno get populated in the textbox as soon as the plot no gets populated I want the gridbox1 which contains customer details of the selected areacode to be populated in the grid for this I have written a servlet
And the servlet code is:
package PlotManagement;
import java.io.*;
import java.sql.ResultSet;
import java.sql.Statement;
import javax.servlet.*;
import javax.servlet.http.*;

import PlotManagement.DBConnection;

public class GetCustomerDetails extends HttpServlet {

public void doGet(HttpServletRequest request,
HttpServletResponse response)throws IOException, ServletException
{
//response.setContentType("application/xml");
PrintWriter out = response.getWriter();
ResultSet rs;
int i=1;
// out.println("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>");
// out.println("<rows>");
try
{
String areacode=request.getParameter("areacode");
String plotno=request.getParameter("plotno");
//String plotno = nplotno.replace( " ","+" );

DBConnection d= new DBConnection();
d.connect();

out.println("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?><rows>");

Statement stmt = d.connection.createStatement();

rs = stmt.executeQuery("SELECT COUNT(b.PropertyId) Prop_Cnt, a.CustomerId,CASE a.OwnerCategory WHEN 1 THEN 'VVIP' WHEN 2 THEN 'VIP' WHEN 3 THEN 'Regular' ELSE 'Missing' END,a.FirstName + ' ' + a.FatherName + ' ' + a.FamilyName CustomerName,a.ArabicName,a.Nationality, a.POBox, a.Emirate, a.OfficeNo,a.ResidenceNo ,a.MobileNo,a.FaxNo,a.Comments, b.OwnerId FROM Property b, Customer a Where b.Customerid = a.Customerid AND b.AreaCode = '"+areacode+"' AND b.PlotNo = '"+plotno+"' AND ISNULL(b.DeleteRecord,0) = 0 AND ISNULL(b.InSewerNetworkRange,0) = 1 GROUP BY a.CustomerId, a.OwnerCategory, a.FirstName, a.FatherName, a.FamilyName,a.ArabicName, a.Nationality, a.POBox, a.Emirate, a.OfficeNo,a.ResidenceNo , a.MobileNo, a.FaxNo, a.Comments, b.OwnerId ORDER BY a.CustomerId");
while ( rs.next())
{
int pcount=rs.getInt(1);
String customerid=rs.getString(2);
String ownercategory=rs.getString(3);
String name=rs.getString(4);
String nameString = name.replace( '&', '*' );
String arabicname=rs.getString(5);
String arabicnameString = arabicname.replace( '&', '*' );
String nationality=rs.getString(6);
int pobox=rs.getInt(7);
String emirate=rs.getString(8);
String officeno=rs.getString(9);
String residenceno=rs.getString(10);
String mobileno=rs.getString(11);
String faxno=rs.getString(12);
String comments=rs.getString(13);
String ownerid=rs.getString(14);



out.print("<row>\n<cell>"+i+"</cell>\n<cell>"+pcount+"</cell>\n<cell>"+customerid+"</cell>\n<cell>"+ownercategory+"</cell>\n<cell>"+nameString+"</cell>\n<cell>"+arabicnameString+"</cell>\n<cell>"+nationality+"</cell>\n<cell>"+pobox+"</cell>\n<cell>"+emirate+"</cell>\n<cell>"+officeno+"</cell>\n<cell>"+residenceno+"</cell>\n<cell>"+mobileno+"</cell>\n<cell>"+faxno+"</cell>\n<cell>"+comments+"</cell>\n<cell>"+ownerid+"</cell>\n</row>\n");
i++;

}
out.print("</rows>");;

d.connection.close();
}

catch(Exception e)
{ e.printStackTrace();
}

}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException {

doGet(request, response);
}



}




But if I call the servlet in the grid onload the initial areacode and plotno fields have null value and the grid is blank but once the user select the areacode how can I trigger the grid to populate itself. Please help me out.
Reply me soon please.






Ruquia
Answer posted by Support on Sep 01, 2008 01:35
>> but once the user select the areacode how can I trigger the grid to populate itself
Something similar to next

function reload_grid(areacode,plotno){
       grid.clearAll(); //delete old data
       grid.loadXML(gridQString+"?areacode="+areacode+"&plotno="+plotno)
}