Calling '.datagrid({...}' will create datagrid component again, it will also make the request to server if the 'url' property is defined. In your case, you can call 'getPanel' method to get the panel object and call 'setTitle' method to change the title.
var p = $('#dg').datagrid('getPanel');
p.panel('setTitlte', title);
If you point the toolbar to a specific <div> element, just like this:
$('#dg').datagrid({
toolbar: '#tb'
});
Thus, you can change the toolbar content easily, the code looks like this:
$('#tb').empty().append(...);
If you really want to re-create the datagrid again, please try this:
var url = dg.datagrid('options').url;
dg.datagrid({
title: title,
toolbar: toolbar,
url: null
});
dg.datagrid('options').url = url; // restore the 'url' again