Grid shows blank line for added record

I have a form bound to a grid. I have a function (“newTask”) that creates a new record in the grid, assigns a temporary unique id, then displays the new form. When the form is complete a second function (“addTask”) adds the record on the server via an ajax call, then after the server confirms that the record is added I am changing the id of the record to the id assigned on the server (via setValues). Then I want to save the form and redisplay the grid.

The functions I have work except that the grid displays a blank record. What do I need to do to get the grid to show the saved record data instead of the blank line?

[code] function newTask() {
var newRecord = {id:dhx.uid()};
$$(“taskgrid”).add(newRecord);
$$(‘taskform’).setValues({
session_no: “RRD1RRNRDNUD9WDN94DR9ER41”,
request_id: “MPTASKADD”,
type: “Call - Outbound”,
date: “02/23/12”,
time: " 800"
});
$$(‘layout_form’).show();
}

    function addTask() {
    //call MPTASKADD
    	var finishTaskURL = "http://pz.southware.com/cgi-nl/NLNET15.BAT";
		var xhr = dhx.ajax().sync().post(finishTaskURL, $$('taskform').getValues());
		text = xhr.responseText;
		newid = text.substr(2,18);
		$$('taskform').setValues({
				id: newid
			});
		if (text.substr(0,2) == "OK") {				
		   $$('taskform').save();
		   $$('layout_grid').show();
		}
		else {
			alert(text);
			};
    }[/code]

try to change order of command as

newid = text.substr(2,18);
//save data back to grid
$$(‘taskform’).save();
$$(‘layout_grid’).show();
//change id
$$(‘layout_grid’).changeId(oldid, newid);

I tried the suggestion and it still doesn’t work - the grid still shows a blank line. Any other suggestions?

it is not clear form the provided code is form linked to grid or filled with data manually.
In second case instead of save you need to use something like

grid.update(id, form.getValues());

In the code above Stanislov suggested:

//change id
$$(‘layout_grid’).changeId(oldid, newid);

I tried to use this to change an ID, but got a script error saying that changeId is not a valid function. How do you change the ID for a grid record when you get a new key value from the server?

Sorry for inconvenience, please use the next code instead

$$(‘layout_grid’).data.changeId(oldid, newid);

Sorry, Stanislav, I’ve tried for a few hours and just can’t seem to make this work. Everything works ok except that the grid still shows a blank record:

  • “layout_grid” is a view that contains a toolbar and “taskgrid” which is a grid
  • “layout_form” is a view that contains a toolbar and “taskform” which is a form
  • taskgrid and taskform are bound together
  • “newTask” is a function that adds a new blank record to the list, populates some of the form fields, and displays the form
  • “addTask” is a function that submits the form data to the server via ajax, gets back an OK and the new key for the added record
  • "addTask then TRIES to save the form with the new key and return to the grid

THE PROBLEM IS ONLY WITH UPDATING/SAVING/DISPLAYING THE GRID DATA for the new record - saving the form with the new key and returning to the grid. I’ve tried numerous ways but the grid always shows a blank line. If I reload the data from the server the added record displays fine in the grid, so the problem is that I can’t get the grid/data updated with the new record (and new record key). In the addTask code you can see that I’ve tried both the normal save and the update function you suggested, and when I run in debug everything works fine until the code after the if-statement.

Please help me if you can. Thank you.

[code] function newTask() {
newRecord = {id:dhx.uid()};
//alert("newRecord: "+newRecord);
$$(“taskgrid”).add(newRecord);
$$(“taskgrid”).select(newRecord);
$$(‘taskform’).setValues({
session_no: “N4D41DUDEUND41MNANA42FU09”,
request_id: “MPTASKADD”,
type: "Call - Outbound “,
date: “03/02/12”,
time: " 800”
});
$$(‘layout_form’).show();
}

    function addTask() {
    	var addTaskURL = "http://pz.southware.com/cgi-nl/NLNET15.BAT";
		var xhr = dhx.ajax().sync().post(addTaskURL, $$('taskform').getValues());
		var text = xhr.responseText;
		var newid = text.substr(2,18);

		if (text.substr(0,2) == "OK") {							   			
			$$('layout_grid').show();
			$$('taskgrid').update(newRecord, $$('taskform').getValues());
			//$$('taskform').save();	
			$$('taskgrid').data.changeId(newRecord, newid);


		
		   	
		}
		else {
			alert(text);
			};
    }[/code]

Please provide a demo link or a full sample, which can be run locally

Here’s a link:
pz.southware.com/cgi-nl/NLNET15. … mpexecmain

Click on the Task option and click the Add button to add a task. The grid adds a blank record, and when you save the form the record is added to the database on the server but doesn’t show in the grid.

Just bumping this topic because of no response last week.

Hello,

the problem looks like you are not adding form values into a grid row.

$$(“taskgrid”).update(id, $$(“taskform”).getValues());

After we called this code, the form values were set in taskgrid.

One more remark - In the bottom toolbar you could set “BottomBar” type instead of BigTabbar. In this case, it will get background color

I thought I was updating. If you’ll notice in the addTask function there is the statement:

$$('taskgrid').update(newRecord, $$('taskform').getValues());

where newRecord is defined in the newTask function as:

newRecord = {id:dhx.uid()};

You said that it worked for you so perhaps I’m not doing this in the right spot. Does the update method need to occur in a particular place in the function?

Thanks for your help. I’m sure this should be simple but I just can’t make it work.

In your code

$$(“taskgrid”).select(newRecord);

must be

$$(“taskgrid”).select(newRecord.id);

and later , you have

$$(“taskgrid”).update(id,

whid must be

$$(“taskgrid”).update(taskgrid.getSelected(),