New column in the Administration > Users default view

Petr Nejedly asked on January 21, 2021 11:13

Hi,

is there a way to add a new column to the default Users view in the Kentico 12 administration, please?

I need to add "Last sign-in" there.

Thanks in advance!

Correct Answer

Juraj Ondrus answered on January 21, 2021 13:44

If you want to add some column to the user list in the User app (module), then you need to create a custom extender for the Users module. Something like described in the documentation on extenders.
The class name you need to adjust is UserListExtender. This class has a method in which the columns are registered:

public override void OnInit()
{
    string[] columns = {
        "UserID",
        "UserName",
        "FullName",
        "Email",
        "UserNickName",
        "UserCreated",
        "UserEnabled",
        @"(CASE 
            WHEN UserPassword IS NULL OR UserPassword = '' THEN 0 
            ELSE 1 
            END) AS UserHasPassword",
        "UserIsExternal",
        "UserIsDomain",
        "UserPrivilegeLevel"
    };
    Control.Columns = columns.Join(", ");
    //...
}

So, you need to create a custom extender which will add required column into that list, for example:

using CMS.Membership.Web.UI;
[assembly: CMS.RegisterCustomClass("MyListExtender", typeof(CustomCode.MyListExtender))]
namespace CustomCode
{
    public class MyListExtender : UserListExtender
    {
        public override void OnInit()
        {
            base.OnInit();
            Control.Columns += ", LastLogon";
        }
    }
}   

And now you just need to adjust the UI to use your extender. Go to Modules application > Users > User interface and then find the Users UI elements as shown on this screen shot and on the Properties tab click the Customize button to edit the settings and select your extender.

0 votesVote for this answer Unmark Correct answer

Recent Answers


Petr Nejedly answered on January 21, 2021 13:46

Perfect, thank you very much!

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.