GenerateIIDForListItem - Отфильтрованная строка - SharePoint - PullRequest
0 голосов
/ 03 апреля 2019

У меня есть некоторый код JavaScript для рендеринга JSLINK в SP 2013. Он работает только тогда, когда таблица нефильтрована.когда таблица фильтруется, GenerateIIDForListItem генерирует неправильный идентификатор, приводя к пустой строке.

Что нужно изменить для отфильтрованной таблицы?

SP.SOD.executeFunc("clienttemplates.js", "SPClientTemplates", function() {

   SPClientTemplates.TemplateManager.RegisterTemplateOverrides({
     OnPostRender: function(ctx) {


    $("table[summary='IT Project Pipeline - Master'] tr td:nth-child(" + PipelineColors_InternalNameIndex("Description", ctx).toString() + ") div").css("height", "60px");
    $("table[summary='IT Project Pipeline - Master'] tr td:nth-child(" + PipelineColors_InternalNameIndex("Description", ctx).toString() + ") div").css("overflow-y", "scroll");
    var risksColumn = PipelineColors_InternalNameIndex("Issue_x0020__x002f__x0020_Risks_", ctx).toString();
    $("table[summary='IT Project Pipeline - Master'] tr td:nth-child(" + risksColumn + ") div").css("height", "60px");
    $("table[summary='IT Project Pipeline - Master'] tr td:nth-child(" + risksColumn + ") div").css("overflow-y", "scroll");


       var rows = ctx.ListData.Row;
       for (var i=0;i<rows.length;i++)
       {

          if ( rows[i]["Current_x000a_Required_x002d_By_"] != null )
          {
              var requiredDate = PipelineColors_ConvertStringDate(rows[i]["Current_x000a_Required_x002d_By_"]);
              var currentDate = new Date();
              var rowId = GenerateIIDForListItem(ctx, rows[i]);
              var row = document.getElementById(rowId); 

              if ( row != null )
              {
                  if ( requiredDate < currentDate )
                  {
                    row.cells[PipelineColors_DisplayNameIndex("Target Date", ctx)].style.backgroundColor = "red";
                  }
                  else if ( requiredDate < currentDate.setDate(currentDate.getDate() + 30) )
                  {
                    row.cells[PipelineColors_DisplayNameIndex("Target Date", ctx)].style.backgroundColor = "yellow";
                  }
              }


          }


       }
     }
   }); 

});

1 Ответ

0 голосов
/ 04 апреля 2019

Попробуйте сначала получить строку.

for (var i=0;i<rows.length;i++)
       {
          var rowId = GenerateIIDForListItem(ctx, rows[i]);
          var row = document.getElementById(rowId);
          if ( rows[i]["Current_x000a_Required_x002d_By_"] != null )
          {
              var requiredDate = PipelineColors_ConvertStringDate(rows[i]["Current_x000a_Required_x002d_By_"]);
              var currentDate = new Date(); 

              if ( row != null )
              {
                  if ( requiredDate < currentDate )
                  {
                    row.cells[PipelineColors_DisplayNameIndex("Target Date", ctx)].style.backgroundColor = "red";
                  }
                  else if ( requiredDate < currentDate.setDate(currentDate.getDate() + 30) )
                  {
                    row.cells[PipelineColors_DisplayNameIndex("Target Date", ctx)].style.backgroundColor = "yellow";
                  }
              }        
          }       
       }
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...