I am using a tree with the connector & dataProcessor. Everything is working successfully when I set the RootItemRelationIDValue = 0 in the connector and update my database to have 0 as the default ParentID value. However I would prefer to use NULL as the default value. So I removed this line
connector.RootItemRelationIDValue = “0”;
in my config and updated my database to have NULL as the default ( root level ) parent id.
This worked fine and renders the tree correctly, but when updating items via the dataProcessor it sets the Parent ID to 0 instead of null
this executes perfectly well but when I refresh my tree this item is no longer visible as it’s parentID is now 0 and not NULL.
According to documentation “In hierarchical data structures sometimes appear the question: what value should be used for indicating the top (root) item. dhtmlxTree(Grid)Connector assumes that the root item’s ParentID value is null”
I am using the .Net Connector and the latest PRO edition which I am still evaluating.
I could probably attach an event and update the value from 0 to NULL but I don’t think that would be the correct fix? Any Suggestions?
Hello,
I think the only solution is to attach event and remove parent id from root items, since dataprocessor always uses 0 as default value for relation id. On the server side it may look as following
public override IdhtmlxConnector CreateConnector(HttpContext context)
{
dhtmlxTreeGridConnector connector = new dhtmlxTreeGridConnector(...);
connector.BeforeProcessing += new EventHandler<DataActionProcessingEventArgs>(connector_BeforeDataActionProcessing);
connector.RootItemRelationIDValue = "null";
return connector;
}
void connector_BeforeDataActionProcessing(object sender, DataActionProcessingEventArgs e)
{
if (e.DataAction.Data[(TableField)"item_parent_id"] == "0")
{
e.DataAction.Data.Remove((TableField)"item_parent_id");
}
}
I tried your recommendation, but tit didn’t work till i tweaked it a bit. This is what I ended up with :
if (e.DataAction.Data.ContainsKey((TableField)ParentIDColumnName) && e.DataAction.Data[(TableField)ParentIDColumnName] == “0”)
e.DataAction.Data[(TableField)ParentIDColumnName] = “null”;
});
Where ParentIDColumnName is a string naming the parent id column. This however proved to be the easy part, as there are other methods which are somewhat inconsistent in their working and users will need to be careful not to be caught out by them, for example :
notice how I had to pass in 0 as the root node, even though the default root node value should be null ( or just empty method deleteChildItems();, but i tried this and it doesn’t work )
The same applieas for refreshItem(itemId) and refreshItems(itemId, source)
In case anyone else has this problem, I too encountered it but solved it by adding the custom SQL using a CASE (if) statement like this:
connector.Request.CustomSQLs.Add(CustomSQLType.Update, "UPDATE OrganisationUnitStructure SET ParentOrgUnitId=CASE WHEN {ParentOrgUnitId}=0 THEN NULL ELSE {ParentOrgUnitId} END, UnitName={UnitName} WHERE Id=" + context.Request.Form[context.Request.Form["ids"] + "_OrganisationUnitStructure_Id"]);
Get a guaranteed answer from DHTMLX technical support team
under the most suitable support plan