Skip to main content
Notice removed Draw attention by CommunityBot
Bounty Ended with Damjan Tomic's answer chosen by CommunityBot
added 41 characters in body
Source Link
John John
  • 1
  • 49
  • 258
  • 603

nowNow i tried this script, where i added it to the miscellaneous tab , and where i replaced the drop-down field with the Title field to eliminate any problem related to the problem offield's internal name VS display name:-

now the above script have partially worked partially, where i can see these issues now:-

  1. the defualt value will not be shown unless i enter a value for one field inside the new row. So is there a way to allow the defualt value to be shown directly once i click on "edit this list" >> and i navigate on ato the new row inside the grid ?

  2. now when i replace the Title with the TrackingStatus the script will not populate any defualt values for the TrackingStatus dropdwon choices. so I am not sure if the problem is with tryingrelated to populate default valuessetting a defualt value for a drop-down field? or the problem that in themy TrackingStatus drop-down field case the field internal name = TrackingStatus while the display name = Tracking Status unlike the title which have the same internal and display name , if so then can you adivce where i need to specify the internal name and where i need to specify the display name inside the script?

now i tried this script, where i added it to the miscellaneous tab , where i replaced the drop-down field with the Title field to eliminate the problem of internal name VS display name:-

now the above script have partially worked, where i can see these issues now:-

  1. the defualt value will not be shown unless i enter a value for one field inside the new row. So is there a way to allow the defualt value to be shown directly once i click on "edit this list" >> and i navigate on a new row inside the grid ?

  2. now when i replace the Title with the TrackingStatus the script will not populate any defualt values for the TrackingStatus dropdwon choices. so I am not sure if the problem is with trying to populate default values for drop-down field? or the problem that in the drop-down field case the field internal name = TrackingStatus while the display name = Tracking Status unlike the title which have the same internal and display name , if so then can you adivce where i need to specify the internal name and where i need to specify the display name inside the script?

Now i tried this script, where i added it to the miscellaneous tab , and where i replaced the drop-down field with the Title field to eliminate any problem related to the field's internal name VS display name:-

now the above script have worked partially, where i can see these issues now:-

  1. the defualt value will not be shown unless i enter a value for one field inside the new row. So is there a way to allow the defualt value to be shown directly once i click on "edit this list" >> and i navigate to the new row inside the grid ?

  2. now when i replace the Title with the TrackingStatus the script will not populate any defualt values for the TrackingStatus dropdwon choices. so I am not sure if the problem is related to setting a defualt value for a drop-down field? or the problem that in my TrackingStatus drop-down field case the field internal name = TrackingStatus while the display name = Tracking Status unlike the title which have the same internal and display name , if so then can you adivce where i need to specify the internal name and where i need to specify the display name inside the script?

added 3276 characters in body
Source Link
John John
  • 1
  • 49
  • 258
  • 603

EDIT.

now i tried this script, where i added it to the miscellaneous tab , where i replaced the drop-down field with the Title field to eliminate the problem of internal name VS display name:-

(function () {

    var overrideCtx = {};
    overrideCtx.Templates = {}; 
    overrideCtx.Templates.OnPreRender = function(ctx) {
        if (!ctx.inGridMode)
        {
            return;
        }
        var statusField = ctx.ListSchema.Field.filter(function(f) {
            return f.Name === 'Title';
        });
        if (statusField.length > 0) {
            for (var i = 0; i < ctx.ListData.Row.length; i++)
            {
                if (ctx.ListData.Row[i].Title == "")
                {               
                    ctx.ListData.Row[i].Title = "Test123";
                }               
            }            
        }
    };

    SPClientTemplates.TemplateManager.RegisterTemplateOverrides(overrideCtx);
})();

SP.SOD.executeFunc('clienttemplates.js', 'SPClientTemplates.TemplateManager.RegisterTemplateOverrides', function() {
        var alreadyAttachedEvent = false;
        SPClientTemplates.TemplateManager.RegisterTemplateOverrides({
            OnPostRender: function(ctx) {               
                if (ctx.enteringGridMode || !ctx.inGridMode || alreadyAttachedEvent)
                  return;
                var jsGrid = null;
                for(var v in g_SPGridInitInfo)
                {
                    var jsGridContainer = $get("spgridcontainer_" + g_SPGridInitInfo[v].jsInitObj.qualifier);
                    var jsGrid = jsGridContainer.jsgrid;
                    break;
                }

                jsGrid.AttachEvent(SP.JsGrid.EventType.OnCellEditCompleted, function(args) {
                    var rec = jsGrid.GetRecord(args.recordKey);
                    if (!rec.properties["Title"].localizedValue)
                    {
                        var update = SP.JsGrid.CreateUnvalidatedPropertyUpdate(args.recordKey,'Title',"Test123",false);
                        jsGrid.UpdateProperties([update], SP.JsGrid.UserAction.UserEdit);
                    }
                });
                alreadyAttachedEvent = true;
            }
        });
    
 });

now the above script have partially worked, where i can see these issues now:-

  1. the defualt value will not be shown unless i enter a value for one field inside the new row. So is there a way to allow the defualt value to be shown directly once i click on "edit this list" >> and i navigate on a new row inside the grid ?

  2. now when i replace the Title with the TrackingStatus the script will not populate any defualt values for the TrackingStatus dropdwon choices. so I am not sure if the problem is with trying to populate default values for drop-down field? or the problem that in the drop-down field case the field internal name = TrackingStatus while the display name = Tracking Status unlike the title which have the same internal and display name , if so then can you adivce where i need to specify the internal name and where i need to specify the display name inside the script?

EDIT.

now i tried this script, where i added it to the miscellaneous tab , where i replaced the drop-down field with the Title field to eliminate the problem of internal name VS display name:-

(function () {

    var overrideCtx = {};
    overrideCtx.Templates = {}; 
    overrideCtx.Templates.OnPreRender = function(ctx) {
        if (!ctx.inGridMode)
        {
            return;
        }
        var statusField = ctx.ListSchema.Field.filter(function(f) {
            return f.Name === 'Title';
        });
        if (statusField.length > 0) {
            for (var i = 0; i < ctx.ListData.Row.length; i++)
            {
                if (ctx.ListData.Row[i].Title == "")
                {               
                    ctx.ListData.Row[i].Title = "Test123";
                }               
            }            
        }
    };

    SPClientTemplates.TemplateManager.RegisterTemplateOverrides(overrideCtx);
})();

SP.SOD.executeFunc('clienttemplates.js', 'SPClientTemplates.TemplateManager.RegisterTemplateOverrides', function() {
        var alreadyAttachedEvent = false;
        SPClientTemplates.TemplateManager.RegisterTemplateOverrides({
            OnPostRender: function(ctx) {               
                if (ctx.enteringGridMode || !ctx.inGridMode || alreadyAttachedEvent)
                  return;
                var jsGrid = null;
                for(var v in g_SPGridInitInfo)
                {
                    var jsGridContainer = $get("spgridcontainer_" + g_SPGridInitInfo[v].jsInitObj.qualifier);
                    var jsGrid = jsGridContainer.jsgrid;
                    break;
                }

                jsGrid.AttachEvent(SP.JsGrid.EventType.OnCellEditCompleted, function(args) {
                    var rec = jsGrid.GetRecord(args.recordKey);
                    if (!rec.properties["Title"].localizedValue)
                    {
                        var update = SP.JsGrid.CreateUnvalidatedPropertyUpdate(args.recordKey,'Title',"Test123",false);
                        jsGrid.UpdateProperties([update], SP.JsGrid.UserAction.UserEdit);
                    }
                });
                alreadyAttachedEvent = true;
            }
        });
    
 });

now the above script have partially worked, where i can see these issues now:-

  1. the defualt value will not be shown unless i enter a value for one field inside the new row. So is there a way to allow the defualt value to be shown directly once i click on "edit this list" >> and i navigate on a new row inside the grid ?

  2. now when i replace the Title with the TrackingStatus the script will not populate any defualt values for the TrackingStatus dropdwon choices. so I am not sure if the problem is with trying to populate default values for drop-down field? or the problem that in the drop-down field case the field internal name = TrackingStatus while the display name = Tracking Status unlike the title which have the same internal and display name , if so then can you adivce where i need to specify the internal name and where i need to specify the display name inside the script?

Tweeted twitter.com/StackSharePoint/status/839879329614086144
Spelling, formatting.
Source Link
Christoffer
  • 9.9k
  • 3
  • 37
  • 53

unable Unable to write a jslink which definedefines a default values for my Dropdown columns inside the Quick Edit grid

I am working on a list view, whichwhere i have a choiceschoice column named "TrackingStatus"TrackingStatus. nowNow for this choice column i define itsdefined the default value to be "In Progress" insieIn Progress from the site columns settings.

butBut i have notednoticed that inside the Quick edit grid the deaultdefault value for the "TrackingStatus"TrackingStatus column will not be rendered (unlike inside the built-in create and edit forms).. so i tried to implement the default values using js linkJS Link as follow:-

1- I upload the following script inside my site collection  :-

(function () {
    alert("1");
    var overrideContext= {};

    overrideContext.Templates = overrideContext.Templates || {};

    overrideContext.Templates.Fields = {
        "TrackingStatus": {
            "View": function (ctx) {if(ctx.CurrentItem.your_column == "")
        return "In Progress";
}
        }
    };

    SPClientTemplates.TemplateManager.RegisterTemplateOverrides(overrideContext);

})();

2- Then i editI edit my list view webpartWebPart and iI provide the following to reference the above js linkJSlink under the WebPart Miscellaneous section  .:-

~sitecollection/Resources/defaultvalues.js

butBut the jslinkJS Link is not having any effect in respect to applying default values for my column, although when iI checked the page source iI can see that the defaultvalues.js is being loaded and i got the alert(1)alert(1) which i intentionaly addI intentionally added inside the JsLink.. .JS Link. so can anyone advice how i

How can I define default values for my choices columns inside the Quick Edit grid  ?

unable to write a jslink which define a default values for my Dropdown columns inside the Quick Edit grid

I am working on a list view, which have a choices column named "TrackingStatus". now for this choice column i define its default value to be "In Progress" insie the site columns settings.

but i have noted that inside the Quick edit grid the deault value for the "TrackingStatus" column will not be rendered (unlike inside the built-in create and edit forms).. so i tried to implement the default values using js link as follow:-

1- I upload the following script inside my site collection  :-

(function () {
    alert("1");
    var overrideContext= {};

    overrideContext.Templates = overrideContext.Templates || {};

    overrideContext.Templates.Fields = {
        "TrackingStatus": {
            "View": function (ctx) {if(ctx.CurrentItem.your_column == "")
        return "In Progress";
}
        }
    };

    SPClientTemplates.TemplateManager.RegisterTemplateOverrides(overrideContext);

})();

2- Then i edit my list view webpart and i provide the following to reference the above js link under the WebPart Miscellaneous section  :-

~sitecollection/Resources/defaultvalues.js

but the jslink is not having any effect in respect to applying default values for my column, although when i checked the page source i can see that the defaultvalues.js is being loaded and i got the alert(1) which i intentionaly add inside the JsLink.. .. so can anyone advice how i can define default values for my choices columns inside the Quick Edit grid  ?

Unable to write a jslink which defines a default values for my Dropdown columns inside the Quick Edit grid

I am working on a list view, where i have a choice column named TrackingStatus. Now for this choice column i defined the default value to be In Progress from the site columns settings.

But i have noticed that inside the Quick edit grid the default value for the TrackingStatus column will not be rendered (unlike inside the built-in create and edit forms).. so i tried to implement the default values using JS Link as follow:

I upload the following script inside my site collection:

(function () {
    alert("1");
    var overrideContext= {};

    overrideContext.Templates = overrideContext.Templates || {};

    overrideContext.Templates.Fields = {
        "TrackingStatus": {
            "View": function (ctx) {if(ctx.CurrentItem.your_column == "")
        return "In Progress";
}
        }
    };

    SPClientTemplates.TemplateManager.RegisterTemplateOverrides(overrideContext);

})();

Then I edit my list view WebPart and I provide the following to reference the above JSlink under the WebPart Miscellaneous section.:

~sitecollection/Resources/defaultvalues.js

But the JS Link is not having any effect in respect to applying default values for my column, although when I checked the page source I can see that the defaultvalues.js is being loaded and i got the alert(1) which I intentionally added inside the JS Link.

How can I define default values for my choices columns inside the Quick Edit grid?

Notice added Draw attention by John John
Bounty Started worth 100 reputation by John John
added 143 characters in body
Source Link
John John
  • 1
  • 49
  • 258
  • 603
Loading
edited tags
Link
John John
  • 1
  • 49
  • 258
  • 603
Loading
deleted 490 characters in body
Source Link
John John
  • 1
  • 49
  • 258
  • 603
Loading
deleted 38 characters in body
Source Link
John John
  • 1
  • 49
  • 258
  • 603
Loading
Source Link
John John
  • 1
  • 49
  • 258
  • 603
Loading