How to show password text as '*' in grid?

1 Answer 359 Views
Grid TextBox
percent
Top achievements
Rank 1
percent asked on 05 Jul 2023, 09:40 AM
How to show password text as '*' in grid Client Detail Templates and Editor Templates.

1 Answer, 1 is accepted

Sort by
0
Alexander
Telerik team
answered on 10 Jul 2023, 06:44 AM

Hi Weijun,

Thank you for reaching out.

Generally, you can achieve the desired outcome by using the built-in templating abilities of the Telerik UI for ASP.NET Core Grid in order to sculpt the textual representation for a given field into '*' characters.

To be more precise, you can achieve the desired outcome by:

  • Creating a common function that will be responsible for altering each of the characters for a given string argument:
<script>
    function replaceString(value){
        value = value.split('').map(function(character){
            return '*';
        }).toString().replace(/,/g , '');

        return value;
    }
</script>
  • Utilize the Columns.Bound.ClientTemplate() API configuration of the Grid and utilize the conventional hash Syntax that is accustomed for the Kendo Templating mechanism. It is important to notice, that for the Detail template, the "#" symbol needs to be escaped:
// Parent Grid Columns

.Columns(columns =>
{
    columns.Bound(e => e.Country).Title("Password").ClientTemplate("#=replaceString(Country)#").Width(110);
})

// Child Grid Columns

.Columns(columns =>
{
    columns.Bound(o => o.ShipAddress).Title("Password").ClientTemplate("\\#=replaceString(ShipAddress)\\#");
})

The aforementioned approach would then produce an identical visual incarnation as the following:

For your convenience, here is a Telerik REPL for Example for you to review that tackles the mentioned above:

As for the Editors, you can explicitly incorporate a custom Editor Template using the following guideline:

You can even use a combination of the following knowledge base article for the editor to toggle between a non-hidden and a hidden state for the password:

Please give the mentioned above suggestions a try and let me know how it works out for you.

Kind Regards,
Alexander
Progress Telerik

As of R2 2023, the default icon type will be SVG instead of Font. See this blogpost for more information.
Tags
Grid TextBox
Asked by
percent
Top achievements
Rank 1
Answers by
Alexander
Telerik team
Share this question
or