LoginSignup
0
2

More than 1 year has passed since last update.

【SharePoint】SharePoint のビューでリストIDをゼロパディングして表示する。

Last updated at Posted at 2018-11-15

2021/06/23 モダン表示の場合を追加しました。

クラシック表示の場合

[JS リンク]を使用する

ビューでページの編集から、表示を変更したいリストの [Web パーツの編集] で [JS リンク] に js ファイルを指定します。

(function () {
  var ctx = {};
  ctx.Templates = {};
  ctx.Templates.Fields = {
    'ID': {
      'View': function (ctx) {
        var num = ctx.CurrentItem.ID;
        return ('000' + num).slice(-4);
      },
    }
  };

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

[集計値]列を使用する 1

[集計値]列を作成して、[数式]を指定します。

例)
="ID-"&TEXT(ID,"0000")

WS000007+%25282%2529[1].JPG

モダン表示の場合

詳細モードで JSON を指定する

列の書式設定で詳細モードを選択して JSON を入力します。

{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
  "elmType": "div",
  "txtContent": "=padStart([$ID], 6, '0')"
}
数値列の場合
{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
  "elmType": "div",
  "txtContent": "=padStart(toString(@currentField), 4, '0')"
}

Power Apps フォームの場合

Text 関数を使います。

DataCard.Default=$fx$
Text(ThisItem.ID, "000000")

参考サイト


  1. 列の設定時にはうまくいきますが、アイテムを編集したりすると'“0”になってしまう不具合があるようです。 

0
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
2