Hello Orlando,
Connectors are not actively developed. Although it is easier to configure a connector for a quick start, you cannot create a complex solution with it. So, it is recommended to use a backend:
https://docs.dhtmlx.com/gantt/desktop__howtostart_guides.html
Hello Ramil, I am starting with dhtmlx and java JSF, started following the contacs-manager demo, i’ll be using dhtmlx -> java servlet -> MSSql server data base.
After initialization and running the servlet on page load, the grid is not populated, its looks like the render_table(“TCiudades”,“id”,“csCodigoCiudad,csDescripcionCiudad,csTipoRiesgo”); is not returning data.
Do you any idea what’s happening, some help, sorry for my bad english.
Initialization page:
dhtmlxEvent(window,“load”,function()
{ //provides the script as a handler of the ‘onload’ HTML event
//dhtmlx.message({ type: “alert”, text: “Starting dhtmlx test” });
var layout,menu,toolbar,contactsGrid,contactForm;
dhtmlx.image_path = "contact_manager/codebase/imgs/";
layout = new dhtmlXLayoutObject(document.body,"2U"); //initializes dhtmlxLayout
layout.cells("a").setText("Contacts"); //sets the text in the header of the 'grid' column
layout.cells("b").setText("Contact Details"); //sets the text in the header of the 'form' column
layout.cells("b").setWidth(500); //sets the width of the 'form' column
menu = layout.attachMenu(); //initializes dhtmlxMenu
menu.setIconsPath("contact_manager/icons/"); //sets the path to custom icons
menu.loadStruct("contact_manager/data/menu.xml"); //loads items from the "data/menu.xml" file to the menu
toolbar = layout.attachToolbar(); //initializes dhtmlxToolbar
toolbar.setIconsPath("contact_manager/icons/"); //sets the path to custom images
toolbar.loadStruct("contact_manager/data/toolbar.xml"); //loads items from the "data/toolbar.xml" file to the toolbar
contactsGrid = layout.cells("a").attachGrid(); //initializes dhtmlxGrid
contactsGrid.setHeader("Codigo,Descripcion,Riesgo"); //sets the headers of columns
contactsGrid.setColumnIds("csCodigoCiudad,csDescripcionCiudad,csTipoRiesgo"); //sets the columns' values //sets the column ids
//contactsGrid.setInitWidths("200,200,*"); //sets the initial widths of columns
contactsGrid.setColAlign("left,left,left"); //sets the horizontal alignment
contactsGrid.setColTypes("ro,ro,ro"); //sets the types of columns
contactsGrid.setColSorting("str,str,str"); //sets the sorting types of columns
contactsGrid.attachHeader("#text_filter,#text_filter,#text_filter"); //sets the filters for columns
contactsGrid.init(); //renders dhtmlxGrid on the page
//----------------- load data from server --------------------//
contactsGrid.load("dhtmlx_Servlet"); //loads data from the "data/contacts.php" file to the grid
//------------------------------------------------------------//
contactForm = layout.cells("b").attachForm(); //initializes dhtmlxForm
contactForm.loadStruct("contact_manager/data/form.xml"); //loads controls, specified in the "data/form.xml" file to the form
contactForm.bind(contactsGrid); //binds the form to the grid
var dpg = new dataProcessor("data/contacts.php"); //inits dataProcessor
dpg.init(contactsGrid); //associates the dataProcessor instance with the grid
dpg.attachEvent("onAfterUpdate", function(sid, action, tid, tag){
if (action == "inserted"){
contactsGrid.selectRowById(tid); //selects a row
contactForm.setFocusOnFirstActive(); //sets focus to the 1st form's input
}
})
contactForm.attachEvent("onButtonClick", function(id){ //attaches a handler function to the "onButtonClick" event
contactForm.save(); //sends the values of the updated row to the server
});
toolbar.attachEvent("onclick",function(id){ //attaches a handler function to the "onclick" event
if(id=="newContact"){ //'newContact' is the id of the button in the toolbar
var rowId=contactsGrid.uid(); //generates an unique id
var pos = contactsGrid.getRowsNum(); //gets the number of rows in the grid
contactsGrid.addRow(rowId,["New contact","",""],pos); //adds a new row to the grid. The 'addRow()' method takes 3 parameters: the row id (must be unique), the initial values of the row, the position where the new must be inserted
};
if(id=="delContact"){ //'delContact' is the id of the button in the toolbar
var rowId = contactsGrid.getSelectedRowId(); //gets the id of the currently selected row
var rowIndex = contactsGrid.getRowIndex(rowId); //gets the index of the row with the specified id
if(rowId!=null){
contactsGrid.deleteRow(rowId); //deletes the currently selected row
if(rowIndex!=(contactsGrid.getRowsNum()-1)){ //checks whether the currently selected row is NOT last in the grid
contactsGrid.selectRow(rowIndex+1,true); //if the currently selected row isn't last - moves selection to the next row
} else{ //otherwise, moves selection to the previous row
contactsGrid.selectRow(rowIndex-1,true)
}
}
}
});
})
</script>
My servlet:
public class dhtmlx_Servlet extends HttpServlet {
/**
* Processes requests for both HTTP <code>GET</code> and <code>POST</code>
* methods.
*
* @param request servlet request
* @param response servlet response
* @throws ServletException if a servlet-specific error occurs
* @throws IOException if an I/O error occurs
*/
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
String data = "**** test ****";
PreparedStatement qps;
ResultSet rs = null;
String city = "test";
String sql;
Connection conn = null;
String username = "psv";
String password = "psv_pw";
com.dhtmlx.connector.GridConnector gc = null ;
response.setContentType("text/html;charset=UTF-8");
/*
try {
InitialContext ctx = new InitialContext();
DataSource ds = (DataSource) ctx.lookup("jdbc/PsFlowWeb");
conn = ds.getConnection(username, password);
sql = "SELECT top 1 *, csDescripcionCiudad as city from TCiudades";
qps = conn.prepareStatement(sql);
rs = qps.executeQuery();
if (rs.next()) {
city = rs.getString("city");
//response.getWriter().write("---- inside rs.next ----");
}
response.getWriter().write(city);
rs.close();
qps.close();
conn.close();
} catch (SQLException ex) {
Logger.getLogger("DashboardDAO").log(Level.SEVERE, null, ex);
} catch (Exception ex) {
Logger.getLogger("DashboardDAO").log(Level.SEVERE, null, ex);
}
*/
//response.getWriter().write(data);
response.setContentType("text/html;charset=UTF-8");
try (PrintWriter out = response.getWriter())
{
try
{
InitialContext ctx = new InitialContext();
DataSource ds = (DataSource) ctx.lookup("jdbc/PsFlowWeb");
conn = ds.getConnection(username, password);
gc = new com.dhtmlx.connector.GridConnector(conn);
gc.servlet(request, response);
//gc.dynamic_loading(100);
gc.enable_log("c:/PSFlow/logs/grid.log", true);
gc.render_table("TCiudades","id","csCodigoCiudad,csDescripcionCiudad,csTipoRiesgo");
}
catch (SQLException | NamingException ex)
{
//Logger.getLogger(SqlServerDAOFactory.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
Hello Orlando,
I specialize in dhtmlxGantt so unfortunately, I can’t really help you with dhtmlxGrid nor Java. You may try posting your question in this category:
https://forum.dhtmlx.com/c/suite/dhtmlxconnector-dataprocessor