I followed the instructions on http://www.codeproject.com/Articles/813090/Master-detail-with-JSGrid to try and create a parent-child edit form of a list in SharePoint.
I set the parent-child web parts under differently, I used the Related Items Web Part for the Quick Edit grid.
I have one set of code that correctly hides columns and sets the default value when I open the edit form but doesn't work when I refresh the page (either F5 or CTRL+F5) - the quick edit grid goes back to the default layout
Type.registerNamespace('Client');
if(typeof(_spBodyOnLoadCalled)=="undefined"||_spBodyOnLoadCalled)
{
window.setTimeout(Client.OnGridLoad,0);
}
_spBodyOnLoadFunctionNames.push("Client.OnGridLoad");
Client.OnGridLoad = function()
{
var viewId = '{1CC372FB-344B-4B0D-8DC6-2614458E130C}';
var orderFieldValue = GetUrlKeyValue("ID"); // ID of the master item
var orderFieldInternalName = "Header"; // Internal name of the lookup field
// Switch to edit view and hide "Add column" button
SP.SOD.executeFunc('inplview', 'InitGridFromView', function() {
g_SPGridInitInfo[viewId].jsInitObj.canUserAddColumn = false;
g_SPGridInitInfo[viewId].jsInitObj.showAddColumn = false;
InitGridFromView(viewId);
});
SP.SOD.executeFunc('clienttemplates.js', 'SPClientTemplates.Utility.ReplaceUrlTokens', function() {
var done = false;
Client.ConfigureGrid(viewId, orderFieldValue, orderFieldInternalName);
// Initialize the variable that stores the objects.
var overrideCtx = {};
overrideCtx.Templates = {};
//OnPostRender call postRenderHandler function.
overrideCtx.OnPostRender = Client.postRenderHandler;
SPClientTemplates.TemplateManager.RegisterTemplateOverrides(Client.postRenderHandler);
});
}
Client.postRenderHandler = function(ctx)
{
alert("postrender");
if (ctx.view != viewId || ctx.enteringGridMode || !ctx.inGridMode || done)
return;
// Hide quick links (aka "hero") row
var hero = $get('Hero-' + ctx.wpq);
var wrapper = document.createElement("div");
wrapper.style.display = 'none';
hero.parentNode.insertBefore(wrapper, hero);
wrapper.appendChild(hero);
// Fetch JSGrid object
var jsGridContainer = $get("spgridcontainer_" + g_SPGridInitInfo[viewId].jsInitObj.qualifier)
var jsGrid = jsGridContainer.jsgrid;
// Automatically update master lookup column
var lock = 0;
jsGrid.AttachEvent(SP.JsGrid.EventType.OnEntryRecordPropertyChanged, function(args) {
if (lock == 0) {
lock = 1;
var update = SP.JsGrid.CreateUnvalidatedPropertyUpdate(args.recordKey,orderFieldInternalName,orderFieldValue,false);
jsGrid.UpdateProperties([update], SP.JsGrid.UserAction.UserEdit);
lock = 0;
}
});
// Make columns non-sortable and non-filterable
var columns = jsGrid.GetColumns();
for (var i in columns)
{
columns[i].isSortable = false;
columns[i].isAutoFilterable = false;
}
jsGrid.UpdateColumns(new SP.JsGrid.ColumnInfoCollection(columns));
// Hide master lookup column
jsGrid.HideColumn(orderFieldInternalName);
done = true;
}
Client.HideHero =function()
{
// Hide quick links (aka "hero") row
var hero = $get('Hero-' + ctx.wpq);
var wrapper = document.createElement("div");
wrapper.style.display = 'none';
hero.parentNode.insertBefore(wrapper, hero);
wrapper.appendChild(hero);
}
Client.ConfigureGrid = function(viewId, orderFieldValue, orderFieldInternalName)
{
Client.HideHero();
// Fetch JSGrid object
var jsGridContainer = $get("spgridcontainer_" + g_SPGridInitInfo[viewId].jsInitObj.qualifier)
if (jsGridContainer==null){alert(viewId);}
var jsGrid = jsGridContainer.jsgrid;
// Automatically update master lookup column
var lock = 0;
jsGrid.AttachEvent(SP.JsGrid.EventType.OnEntryRecordPropertyChanged, function(args) {
if (lock == 0) {
lock = 1;
var update = SP.JsGrid.CreateUnvalidatedPropertyUpdate(args.recordKey,orderFieldInternalName,orderFieldValue,false);
jsGrid.UpdateProperties([update], SP.JsGrid.UserAction.UserEdit);
lock = 0;
}
});
// Make columns non-sortable and non-filterable
var columns = jsGrid.GetColumns();
for (var i in columns)
{
columns[i].isSortable = false;
columns[i].isAutoFilterable = false;
}
jsGrid.UpdateColumns(new SP.JsGrid.ColumnInfoCollection(columns));
// Hide master lookup column
jsGrid.HideColumn(orderFieldInternalName);
done = true;
}
and I have one set of code that works the opposite way around
SP.SOD.executeFunc('clienttemplates.js', 'SPClientTemplates.Utility.ReplaceUrlTokens', function() {
function init()
{
_spBodyOnLoadFunctions.push(function()
{
var viewId = '{1CC372FB-344B-4B0D-8DC6-2614458E130C}';
var orderFieldValue = GetUrlKeyValue("ID"); // ID of the master item
var orderFieldInternalName = "Header"; // Internal name of the lookup field
// Switch to edit view and hide "Add column" button
SP.SOD.executeFunc('inplview', 'InitGridFromView', function() {
g_SPGridInitInfo[viewId].jsInitObj.canUserAddColumn = false;
g_SPGridInitInfo[viewId].jsInitObj.showAddColumn = false;
InitGridFromView(viewId);
});
SP.SOD.executeFunc('clienttemplates.js', 'SPClientTemplates.TemplateManager.RegisterTemplateOverrides', function() {
var done = false;
SPClientTemplates.TemplateManager.RegisterTemplateOverrides({
OnPostRender: function(ctx) {
if (ctx.view != viewId || ctx.enteringGridMode || !ctx.inGridMode || done)
return;
// Hide quick links (aka "hero") row
var hero = $get('Hero-' + ctx.wpq);
var wrapper = document.createElement("div");
wrapper.style.display = 'none';
hero.parentNode.insertBefore(wrapper, hero);
wrapper.appendChild(hero);
// Fetch JSGrid object
var jsGridContainer = $get("spgridcontainer_" + g_SPGridInitInfo[viewId].jsInitObj.qualifier)
var jsGrid = jsGridContainer.jsgrid;
// Automatically update master lookup column
var lock = 0;
jsGrid.AttachEvent(SP.JsGrid.EventType.OnEntryRecordPropertyChanged, function(args) {
if (lock == 0) {
lock = 1;
var update = SP.JsGrid.CreateUnvalidatedPropertyUpdate(args.recordKey,orderFieldInternalName,orderFieldValue,false);
jsGrid.UpdateProperties([update], SP.JsGrid.UserAction.UserEdit);
lock = 0;
}
});
// Make columns non-sortable and non-filterable
var columns = jsGrid.GetColumns();
for (var i in columns)
{
columns[i].isSortable = false;
columns[i].isAutoFilterable = false;
}
jsGrid.UpdateColumns(new SP.JsGrid.ColumnInfoCollection(columns));
// Hide master lookup column
jsGrid.HideColumn(orderFieldInternalName);
done = true;
}
});
});
});
}
RegisterModuleInit(SPClientTemplates.Utility.ReplaceUrlTokens("~site/SiteAssets/Scripts/Parent_Child/Project_Timesheets.js"), init);
init();
});I am now struggling to see what is causing the difference.
I don't believe MDS is the problem.
I do know that, in the first code, it is falling over at
var jsGridContainer = $get("spgridcontainer_" + g_SPGridInitInfo[viewId].jsInitObj.qualifier)But I can't debug it (not even using F12, my browser is throwing an error).
I don't have access to the SharePoint installation or support from my IT, I have to do all of this from outside the environment.
Any suggestions?