Grid/Form dataprocessor

I have a grid/form/dataprocessor working together but just noticed the following problem. When loading the page I create the dataProcessor and bind it with the grid. When displaying the form I use form.bind(grid) then form.save().

The problem is the form has more fields than the grid and I noticed the dataProcessor is being sent only the grid columns (subset of the form fields). What is the best solution to get all 3 of these working together?

You can use dhtmlxdatastore with dataprocessor, after that bind form to store and sync grid with store.

grid.sync(store);
grid.attachEvent("onRowSelect", function(id){
    store.setCursor(id);
});
form.bind(store);

As result form will show and save all values, and grid will show actual data as well ( editing data in grid will trigger data saving as well )

Are there any limitations with datastore and smart/dynamic rendering? I was using a data store at one point but switched possibly to get dynamic rendering to work (can’t remember exactly).

In latest version there must not be any limitations.
You can use sync grid with datastore which does use dynamical data loading ( dyn. loading configured for the store, not for the grid )

I’m not sure where I asked this originally but I’ll a follow up here.

obj = form.getFormData();
var recid = (new Date()).valueOf();
obj.id = recid;
datastore.add(obj);
grid.selectRow(grid.getRowIndex(recid));

So all the above is working, adds a record to datastore/grid and selects the newly added row.

Question, after the above is there a way to get the record id returned from the data processor? Data processor is passed sid and returns tid so I just need to get the tid at this point.

You need to catch the necessary moment.

dp.attachEvent("onAfterUpdate", function(tid){ //will be called after data saving on server side alert(tid); });

Another question related to my setup above. My grid has a few columns of type dhxCalendar. The field is defined in the form with these 3 parameters (and some others)

type: ‘calendar’,
dateFormat:’%Y-%m-%d’,
serverdateFormat:’%Y-%m-%d’

When using form.save() the date fields are sent to the DP with the correct format. However, my form has an additional date field which is not on the grid and that is being saved as “Tue Jul 16 2013 14:10:00 GMT-0700 (Pacific Standard Time)”. How do I get those dates to format properly?

It is a bit complicated.
Form can return dates as date objects or as formatted strings.
To have correct integration with calendar columns in grid - it must be a date object, but for saving not linked to grid fields - you need the formatted string.

Try to add the next line after form.bind

form.getValues = function(){ return this.getFormData(true, true); };

That allowed the date to send properly. What are my options for also adding a time value? I think my problem is having both a date only and datetime value on the same record type. This seems to be working on another grid which only has 1 datetime field, but the grid I’m working on now has 2 date fields and 1 datetime field, so its setDateFormat uses date only.

var obj = form.getFormData();
obj.AlarmTime.setHours(obj.alarmhour);
obj.AlarmTime.setMinutes(obj.alarmminute);

The above works on another grid which only has datetime values

With above custom getValues method, date part will be returened as string, not as date object
So you can add hours and minutes info like next

form.getValues = function(){ var obj = this.getFormData(true, true); obj.AlarmTime += " "+obj.alarmhour+":"+obj.alarmminute; return obj; };

That worked, for adding new records I am having a similar problem, maybe because its not saving directly to the grid but not sure where to specify a format or bind if that’s even needed.

var obj = form.getFormData();

if(edit)
{
form3e.setFormData(obj); //This saves dates in correct format “YYYY-MM-DD”
form3e.save();
}
else
datastore.add(obj); //This sends date with wrong format to datastore

Is obj, in the above code snippet, obtained by the form.getFormData(true, true); call or in some other way ?

It’s called by this var obj = form.getFormData();

I found a workaround using this but still trying to find a generic way to do it so I don’t need to specify the field name for each date field.

if(obj.datefield) obj.datefield= obj.datefield.toISOString();
datastore.add(obj)

Please try to change the code as

if(edit){ form3e.setFormData( form.getFormData() ); form3e.save(); } else datastore.add( form.getFormData(true, true) );

With above code it will use date as object in the form, but will use date as correctly formatted string during adding to the datastore