Hi Stanislav,
I’m using both a datastore - so that the form and grid may exchange data - and a dataprocessor. The problem seems to occur on only newly-created rows, but looking at the database, there doesn’t seem to be a problem with new ID generation. I’ll try enabling logging to investigate further as you suggested. Here’s all the code - please let me know if anything looks wrong, thank you:
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<title>FRST Datastore test</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<style type="text/css">
div.marginl {margin-left:20pt;}
</style>
<!-- Layout -->
<link rel="stylesheet" type="text/css" href="./dhtmlxLayout/dhtmlxLayout/codebase/dhtmlxlayout.css">
<link rel="stylesheet" type="text/css" href="./dhtmlxLayout/dhtmlxLayout/codebase/skins/dhtmlxlayout_dhx_skyblue.css">
<script src="./dhtmlxLayout/dhtmlxLayout/codebase/dhtmlxcommon.js"></script>
<script src="./dhtmlxLayout/dhtmlxLayout/codebase/dhtmlxlayout.js"></script>
<!-- Tab bar -->
<link rel="STYLESHEET" type="text/css" href="./dhtmlxTabbar/dhtmlxTabbar/codebase/dhtmlxtabbar.css">
<script src='./dhtmlxTabbar/dhtmlxTabbar/codebase/dhtmlxcommon.js'></script>
<script src='./dhtmlxTabbar/dhtmlxTabbar/codebase/dhtmlxtabbar.js'></script>
<script src='./dhtmlxTabbar/dhtmlxTabbar/codebase/dhtmlxcontainer.js'></script>
<!-- Grid -->
<link rel='stylesheet' type='text/css' href='./dhtmlxGrid/dhtmlxGrid/codebase/dhtmlxgrid.css'>
<link rel='stylesheet' type='text/css' href='./dhtmlxGrid/dhtmlxGrid/codebase/skins/dhtmlxgrid_dhx_skyblue.css'>
<link rel='stylesheet' type="text/css" href='./dhtmlxGrid/dhtmlxGrid/samples/common/css/style.css' media="screen" />
<script src='./dhtmlxGrid/dhtmlxGrid/codebase/dhtmlxcommon.js'></script>
<script src='./dhtmlxGrid/dhtmlxGrid/codebase/dhtmlxgrid.js'></script>
<script src='./dhtmlxGrid/dhtmlxGrid/codebase/dhtmlxgridcell.js'></script>
<script src='./dhtmlxGrid/dhtmlxGrid/codebase/ext/dhtmlxgrid_validation.js' type='text/javascript' charset='utf-8'></script>
<script src='./dhtmlxGrid/dhtmlxGrid/samples/common/data.js'></script>
<script src='./dhtmlxGrid/dhtmlxGrid/codebase/ext/dhtmlxgrid_srnd.js'></script>
<script src='./dhtmlxGrid/dhtmlxGrid/codebase/ext/dhtmlxgrid_filter.js'></script>
<script src='./dhtmlxGrid/dhtmlxGrid/codebase/ext/dhtmlxgrid_form.js'></script>
<!-- Form -->
<link rel='stylesheet' type='text/css' href='./dhtmlxForm/dhtmlxForm/codebase/skins/dhtmlxForm_dhx_skyblue.css'>
<script src='./dhtmlxForm/dhtmlxForm/codebase/dhtmlxcommon.js'></script> <!--Ensure form libraries are placed after tab, grid libraries-->
<script src='./dhtmlxForm/dhtmlxForm/codebase/dhtmlxform.js'></script>
<!-- Datastore -->
<script src='./datastore/datastore.js'></script>
<!-- Dataprocessor -->
<script src='./dhtmlxGrid/dhtmlxdataprocessor/sources/dhtmlxdataprocessor.js'></script>
<!-- Dataconnector -->
<script src='./dhtmlxConnector_php_v15_120612/php/codebase/connector.js'></script>
<style>
div#tabbar {
position: relative;
width: 600px;
height: 400px;
margin-left: 20px;
margin-top: 20px;
}
</style>
<script>
var dhxLayout;
var myForm, formData;
var myGrid;
var dhxTabbar;
var obj;
var myuid;
function doOnLoad() {
// Initialise datastore.
var contacts = new dhtmlXDataStore({
url:"connectorFRST2.php",
datatype:"xml"
});
// Set default grid data scheme.
contacts.data.scheme({
LName: "Enter new contact",
FName: "",
DOB: "",
Moniker: "",
Offenses: "",
ContactID: myuid //(new Date()).valueOf(), //"123",
});
var myDP = new dataProcessor("connectorFRST2.php");
myDP.init(contacts);
// Set 'Contact' form data.
formData = [{
type: "settings",
position: "label-left",
labelWidth: 145,
inputWidth: 375
}, {
type: "block",
inputWidth: "auto",
list: [{
type: "input",
name: "LName",
label: "Last Name"
}, {
type: "input",
name: "FName",
label: "First Name"
}, {
type: "input",
name: "DOB",
label: "Date of Birth"
}, {
type: "input",
name: "Moniker",
label: "Moniker"
}, {
type: "input",
name: "Offenses",
label: "Offenses"
}, {
type: "hidden",
name: "ContactID",
label: "Contact ID"
}, {
type: "block", list:[{
type: "button", offsetTop:8, name:"add", value:"add"
}, {
type: "newcolumn"
}, {
type: "button", name:"change", offsetTop:8, value:"change"
}, {
type: "newcolumn"
}, {
type: "button", name:"delete", offsetTop:8, value:"delete"
}, {
type: "newcolumn"
}, {
type: "button", name:"clear", offsetTop:8, value:"clear"
}]
}]
}];
// To attach forms and grids to the tab bar, see:
// http://www.dhtmlx.com/docs/products/dhtmlxForm/samples/05_integration/05_split.html#code
// http://dhtmlx.com/docs/products/dhtmlxTabbar/samples/05_components/01_grid_inside.html
// To attach layout to tabbar, see:
// http://www.dhtmlx.com/docs/products/dhtmlxLayout/samples/04_components/04_tabbar.html
// Initialise layout.
dhxLayout = new dhtmlXLayoutObject("parentId", "2U");
dhxLayout.cells("a").setText("Contact Search");
// Attach tab bar to layout and initialise tab bar.
//dhxTabbar = new dhtmlXTabBar("tabbar");
dhxTabbar = dhxLayout.cells("b").attachTabbar();
dhxTabbar.setImagePath("./dhtmlxTabbar/dhtmlxTabbar/codebase/imgs/");
dhxTabbar.setSkin("dhx_skyblue");
dhxTabbar.addTab("a1", "Contact", 70);
dhxTabbar.addTab("a2", "Referrals", 70);
dhxTabbar.addTab("a3", "Notes", 70);
dhxTabbar.addTab("a4", "Reports", 70);
dhxTabbar.setTabActive("a1");
// Attach 'Contact Search' grid to layout and initialise grid.
myGrid = dhxLayout.cells("a").attachGrid();
myGrid.setImagePath("./dhtmlxGrid/dhtmlxGrid/codebase/imgs/");
myGrid.setHeader("Last Name,First Name,Date of Birth");
myGrid.setInitWidths("250,250,90");
myGrid.setColumnIds("LName,FName,DOB");
myGrid.attachHeader("#text_filter,#text_filter,#text_filter");
myGrid.enableAutoWidth(true);
myGrid.setColAlign("left,left,right");
myGrid.setColTypes("ro,ro,ro");
myGrid.setColSorting("str,str,date");
myGrid.setSkin("dhx_skyblue");
myGrid.init();
//myGrid.enableStableSorting(true);
//myGrid.sortRows(0,"str","asc");
// Attach 'Contact' form to tab bar.
myForm = dhxTabbar.cells("a1").attachForm(formData);
// Attach 'Referrals' grid to tab bar and initialise grid.
// 2013.01.03 - it appears it will be necessary to create another PHP dataprocessor script to source data from the 'referrals' table, then use an event handler
// in the main grid to load data into the second grid. See http://stackoverflow.com/questions/12226273/how-to-refresh-reload-dhtmlx-grid.
// myGrid.loadXML("connectorFRST2a.php", function(){myGrid2.sortRows(0);}); <-- will need to pass ContactID value somehow to connectorFRST2a.php. See http://forum.dhtmlx.com/viewtopic.php?f=19&t=14993.
var myGrid2 = dhxTabbar.cells("a2").attachGrid();
myGrid2.setImagePath("./dhtmlxGrid/dhtmlxGrid/codebase/imgs/");
myGrid2.setHeader("Assistance,Referrals,Contract Date,Follow Up");
//myGrid2.setHeader("Assistance");
myGrid2.setInitWidths("100,300,100,100");
myGrid2.attachHeader("#select_filter,#text_filter,#text_filter,#text_filter");
myGrid2.enableAutoWidth(true);
myGrid2.setColAlign("left,left,right,right");
myGrid2.setColTypes("ro,ro,ro,ro");
myGrid2.setColSorting("str,str,date,date");
myGrid2.setSkin("dhx_skyblue");
myGrid2.init();
myGrid.attachEvent("onRowSelect", function(){
//alert('click event!');
//myGrid2.loadXML("connectorFRST2a.php?id="+myGrid.getSelectedRowId();
return true;
});
//myGrid.loadXML("./dhtmlxGrid/dhtmlxGrid/myGrid1.xml");
// All about data binding and dhtmlxdatastore:
// http://docs.dhtmlx.com/doku.php?id=binding.
// http://docs.dhtmlx.com/doku.php?id=dhtmlxdatastore:binding_components_to_dhtmlxdatastore
// http://docs.dhtmlx.com/doku.php?id=dhtmlxdatastore:crud_operations_in_bound_components
// http://docs.dhtmlx.com/doku.php?id=dhtmlxdatastore:step-by-step_example <-- EXAMPLE
// http://docs.dhtmlx.com/doku.php?id=dhtmlxdatastore:datastore_example_server-side <-- BETTER EXAMPLE
// http://forum.dhtmlx.com/viewtopic.php?f=19&t=24229 <-- How to capture ID after an add.
// http://forum.dhtmlx.com/viewtopic.php?f=17&t=23096&p=74242&hilit=datastore+add+record#p74242 <-- How to add form data to datastore.
myGrid.sync(contacts);
myForm.bind(myGrid);
contacts.attachEvent("onXLE", function(){
contacts.sort("#LName#","asc"); // Sort data by last name upon load.
});
myForm.attachEvent("onButtonClick", function(id){
if (id=='add'){
//myForm.clear();
var myuid = (new Date()).valueOf();
myForm.setItemValue("ContactID", myuid);
//contacts.add({}); // Creates a new record that uses 'employees.data.scheme'.
obj = myForm.getFormData();
obj.id = myuid; // Both datastore and grid expect the "id" property on the data object.
contacts.add(obj);
contacts.sort("#LName#","asc");
// http://forum.dhtmlx.com/viewtopic.php?f=14&t=9526&start=10 <-- Get, select row index.
// http://docs.dhtmlx.com/doku.php?id=dhtmlxgrid:rows_manipulation <-- Row manipulation methods.
myGrid.selectRow(myGrid.getRowIndex(myuid),false,false,true);
}
else if (id=='change'){
myForm.save(); // Saves the form data changes.
}
else if (id=='delete'){ // Deletes the selected row.
var selectedItem = myGrid.getSelectedRowId();
contacts.remove(selectedItem);
}
else if (id=='clear'){
myForm.clear();
}
});
}
</script>
</head>
<body onLoad="doOnLoad()">
<div class="header">
<a class="logo" href="http://intranet" title="City of Fontana Intranet"><img src="http://intranet/images/fontana_logo.jpg" height="79%" border="0"/></a>
<div class="tittle-dhtmlx">City of Fontana - FRST Datastore test</div>
</div>
<!--div class='marginl' style="display:block;">
<h3>FRST Contact Manager</h3>
</div-->
<div id="parentId" style="position: relative; top: 20px; left: 20px; width: 1225px; height: 425px; aborder: #B5CDE4 1px solid;"></div>
<!--div id="tabbar"></div-->
</body>
</html>