title: How to fire loadComplete after new row is added in jqgrid?
body: <p>I have a custom formatter that fire inside loadComplete of jqgrid. Need the same custom formatter to work when a row is dynamically added too. So i was thinking to call loadComplete() like any normal function. Custom formatter works well when grid is loaded, but does not take effect when a row is added later. </p>
  
  <p>add row dynamically</p>
  
  <pre><code>function addRow(cfgid,cfgname,hostname,osname,cfgDesc,productId,cfgType,updateDate,emailAddress,absolutePath,fileName,productVersion,converted)
  {
  
      var myrow = {cfgId:cfgid, '':'', cfgName:cfgname, hostname:hostname, osname:osname, cfgDesc:cfgDesc, productId:productId,hostname:hostname,cfgType:cfgType,updateDate:updateDate,emailAddress:emailAddress,absolutePath:absolutePath,fileName:fileName,productVersion:productVersion,converted:converted};
  
      $("#list1").addRowData(cfgid, myrow,"first");
      //$("#list1").loadComplete(); does not work
      $("#list1").trigger("reloadGrid");
      $("#list1").sortGrid('updateDate', true, 'desc');
  
  }
  </code></pre>
  
  <p>JqGrid</p>
  
  <pre><code>function drawDynamicGrid(xml)
  {
      var emptyMsgDiv = $('&lt;div&gt;No configurations loaded&lt;/div&gt;');
  
      var xmlObject=StringtoXML(xml);
      var getColumnIndexByName = function (grid, columnName) {
          var cm = grid.jqGrid('getGridParam', 'colModel'), i = 0, l = cm.length;
          for (; i &lt; l; i += 1) {
              if (cm[i].name === columnName) {
                  return i; // return the index
              }
          }
          return -1;
      },
      grid = jQuery("#list1"),
      convertIcon = '&lt;span class="ui-state-default" style="border:0" id="converted"&gt;&lt;span class="ui-icon ui-icon-info" style="float: left; margin-right: .3em;"&gt;&lt;/span&gt;&lt;/span&gt;',
      iconAlert = '&lt;span class="ui-state-error" style="border:0" id="expired"&gt;&lt;span class="ui-icon ui-icon-alert" style="float: left; margin-right: .3em;"&gt;&lt;/span&gt;&lt;/span&gt;';
      grid.jqGrid({
  
        datastr : xml,
        datatype: 'xmlstring',
        colNames:['cfgId','Name', 'Host','Operating System', 'Description','Product', 'Type', 'Last Updated Time','Last Updated By','','','',''],
        colModel:[
            {name:'cfgId',index:'cfgId', width:90, align:"left", hidden:true},
            {name:'cfgName',index:'cfgName', width:80, align:"left", formatter: 'showlink', formatoptions: {baseLinkUrl: '#'} },
            {name:'hostname',index:'hostname', width:70, align:"left"},
            {name:'osname',index:'osname', width:90, align:"left"},
            {name:'cfgDesc',index:'cfgDesc', width:80, align:"left"},
            {name:'productId',index:'productId', width:40, align:"left"},
            {name:'cfgType',index:'cfgType', width:50, align:"left"},
            {name:'updateDate',index:'updateDate',sorttype:'Date', width:120, align:"left"},
            {name:'emailAddress',index:'emailAddress', width:120, align:"left"},
            {name:'absolutePath',index:'absolutePath', width:90, align:"left", hidden:true},
            {name:'fileName',index:'fileName', width:10, align:"left", hidden:true},
            {name:'productVersion',index:'productVersion', width:10, align:"left", hidden:true},
            {name:'converted',index:'converted', width:10, align:"left", hidden:true}
        ],
        pager : '#gridpager',
        rowNum:10,
        rowList:[10,50,100],
        scrollOffset:0,
        height: 'auto',
        emptyrecords: 'No configurations loaded',
        autowidth:true,
        viewrecords:true,
        gridview: true,
        multiselect: true,
        xmlReader: {
            root : "list",
            row: "Response",
            id: "cfgId",
            userdata: "userdata",
            repeatitems: false
        },
  
        loadComplete: function () {
  
              var count = grid.jqGrid('getGridParam');
              var ts = grid[0];
              if (ts.p.reccount === 0) {
                  grid.hide();
                  emptyMsgDiv.show();
              } else {
                  grid.show();
                  emptyMsgDiv.hide();
              }
  
              //for showlink and icon alert having date difference more than 90 days
              var iRow, row, trClasses, $cell,
              icfgName = getColumnIndexByName(grid, 'cfgName'),
              iupdateDate = getColumnIndexByName(grid, 'updateDate'),
              iconverted = getColumnIndexByName(grid, 'converted'),
  
              mygrid = grid[0],
              rows = mygrid.rows,
              cRows = rows.length,
              myLink = function (e) {
                  var $td = $(e.target).closest('td'),
                      text = $td.text(),
                      $tr = $td.closest('tr'),
                      rowid = $tr[0].id;
                      goToViewAllPage(rowid);
              };
          for (iRow = 0; iRow &lt; cRows; iRow += 1) {
              row = rows[iRow]; // row.id is the rowid
              trClasses = row.className.split(' ');
              if ($.inArray('jqgrow', trClasses) &gt; 0) {
                  // the row is a standard row (only if subGrid:true are used)
                  var cellvalue1,firstDate,secondDate;
                  $cell = $(row.cells[icfgName]);
                  cellvalue1=$(row.cells[iupdateDate]).text();
                  firstDate = new Date();
                  //console.info(cellvalue1+", "+cellvalue1.length);
                  //var cellvalue1="08-18-2011 11:49:01";
                  var convertedText=$(row.cells[iconverted]).text();
                  if(cellvalue1.length&gt;25)
                  {
  
                      secondDate=new Date();
                      //secondDate = secondDate.substring(0, secondDate.length-3);
  
                      if(diffOf2Dates(firstDate,secondDate,true)&gt;=expireCondition)
                      {
                          $cell.prepend(iconAlert);
                      }
                      $cell.click(myLink);
                  }
                  else
                  {
                      if(cellvalue1.length!=1)
                      {
  
                          secondDate = cellvalue1.substring(0, cellvalue1.length-6);
                          if(diffOf2Dates(firstDate,secondDate,false)&gt;=expireCondition)
                          {
                              $cell.prepend(iconAlert);
                          }
                          $cell.click(myLink);
                      }
  
                      //I want to add this Icon when a new row is added using addRowData
                      if(convertedText=="yes"&amp;&amp;supportEng)$cell.prepend(convertIcon);
  
  
                  }
              }
          }
  
          }
      });
      grid.jqGrid('navGrid','#gridpager',{edit:false,add:false,del:false});
  
      var myGrid = $("#list1");
      $("#cb_"+myGrid[0].id).hide();
      // place div with empty message insde of bdiv
      emptyMsgDiv.insertAfter(grid.parent());
  
      $("#list1").trigger("reloadGrid");
      $("#list1").sortGrid('updateDate', true, 'desc');
      $("#list1").setGridParam({rowNum:10});
  
  }
  </code></pre>
  
  <p><strong>Update</strong></p>
  
  <p>Server Response</p>
  
  <pre><code>&lt;list&gt;
    &lt;Response&gt;
      &lt;cfgId&gt;1223&lt;/cfgId&gt;
      &lt;cfgName&gt;ld&lt;/cfgName&gt;
      &lt;cfgDesc&gt;fhdf&lt;/cfgDesc&gt;
      &lt;cfgType&gt;Production&lt;/cfgType&gt;
      &lt;fileName&gt;4.xml&lt;/fileName&gt;
      &lt;absolutePath&gt;../../../xmlrepository/121/4_ver3.xml&lt;/absolutePath&gt;
      &lt;emailAddress&gt;mk@aol.com&lt;/emailAddress&gt;
      &lt;projectId&gt;121&lt;/projectId&gt;
      &lt;hostname&gt;abc-dev-01.24hourfit.com&lt;/hostname&gt;
      &lt;createDate&gt;2012-12-07 12:15:48.0 IST&lt;/createDate&gt;
      &lt;updateDate&gt;2012-12-07 12:15:48.0 IST&lt;/updateDate&gt;
      &lt;state&gt;1&lt;/state&gt;
      &lt;productId&gt;3&lt;/productId&gt;
      &lt;osname&gt;Linux&lt;/osname&gt;
      &lt;productVersion&gt;1.0 HotFix5&lt;/productVersion&gt;
      &lt;converted&gt;yes&lt;/converted&gt;
    &lt;/Response&gt;
    &lt;Response&gt;
      &lt;cfgId&gt;1224&lt;/cfgId&gt;
      &lt;cfgName&gt;DD&lt;/cfgName&gt;
      &lt;cfgDesc&gt;dfsd&lt;/cfgDesc&gt;
      &lt;cfgType&gt;Production&lt;/cfgType&gt;
      &lt;fileName&gt;2.xml&lt;/fileName&gt;
      &lt;absolutePath&gt;../../../xmlrepository/121/2_ver1.xml&lt;/absolutePath&gt;
      &lt;emailAddress&gt;mk@aol.com&lt;/emailAddress&gt;
      &lt;projectId&gt;121&lt;/projectId&gt;
      &lt;hostname&gt;vkeh-jam&lt;/hostname&gt;
      &lt;createDate&gt;2012-12-07 12:21:31.0 IST&lt;/createDate&gt;
      &lt;updateDate&gt;2012-12-07 12:21:31.0 IST&lt;/updateDate&gt;
      &lt;state&gt;1&lt;/state&gt;
      &lt;productId&gt;3&lt;/productId&gt;
      &lt;osname&gt;HP-UX&lt;/osname&gt;
      &lt;productVersion&gt;5.0&lt;/productVersion&gt;
      &lt;converted&gt;no&lt;/converted&gt;
    &lt;/Response&gt;
  &lt;/list&gt;
  </code></pre>
  
  <p>goToViewAllPage function </p>
  
  <pre><code>function goToViewAllPage(rowid)
  {
      var pageLoadContent='&lt;table id="detailTable" width="100%"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td align="center"&gt;Please Wait&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td align="center"&gt;&lt;img src="/informaticaCSM/infa9/csm/view/include/images/loading.gif" alt="Loading"/&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;';
      //rowid=rowid.substring(4, rowid.length);
      $("#nextPageLoading").pageLoad({content:pageLoadContent});
      $("#nextPageLoading").css({"cursor":"wait"});
      $("#pageLoadingBackground").css({"cursor":"wait"});
  
      var rowData = jQuery("#list1").getRowData(rowid); 
      configid = rowData['cfgId'];
      configname=rowData['cfgName'];
      configdesc=rowData['cfgDesc'];
      configenv=rowData['cfgType'];
      filename=rowData['fileName'];
      updatedate=rowData['updateDate'];
      absolutepath=rowData['absolutePath'];
      productname=rowData['productId'];
      productversion=rowData['productVersion'];
      converted=rowData['converted'];
  
      //emailid=rowData['emailAddress'];
      emailid=logid;
  
      var form_ref=document.createElement("form");
      form_ref.id="viewform";
      form_ref.name="viewform";
      form_ref.action=redirectMainUrl+"showResult.action";
      form_ref.method="post";
      form_ref.target="_self";
      document.body.appendChild(form_ref);
  
      var cfgstField = document.createElement("input");
      cfgstField.name="sessiontoken";
      cfgstField.type="hidden";
      cfgstField.value=sessiontoken;
      form_ref.appendChild(cfgstField);
  
      var cfgidField = document.createElement("input");
      cfgidField.name="cfgid";
      cfgidField.type="hidden";
      cfgidField.value=configid;
      form_ref.appendChild(cfgidField);
  
      var cfgnameField = document.createElement("input");
      cfgnameField.name="cfgname";
      cfgnameField.type="hidden";
      cfgnameField.value=configname;
      form_ref.appendChild(cfgnameField);
  
      var cfgdescField = document.createElement("input");
      cfgdescField.name="cfgdesc";
      cfgdescField.type="hidden";
      cfgdescField.value=configdesc;
      form_ref.appendChild(cfgdescField);
  
      var cfgenvField = document.createElement("input");
      cfgenvField.name="cfgenv";
      cfgenvField.type="hidden";
      cfgenvField.value=configenv;
      form_ref.appendChild(cfgenvField);
  
      var cfgfileField = document.createElement("input");
      cfgfileField.name="cfgfile";
      cfgfileField.type="hidden";
      cfgfileField.value=filename;
      form_ref.appendChild(cfgfileField);
  
      var cfgabsField = document.createElement("input");
      cfgabsField.name="absFileName";
      cfgabsField.type="hidden";
      cfgabsField.value=absolutepath;
      form_ref.appendChild(cfgabsField);
  
      var cfgdateField = document.createElement("input");
      cfgdateField.name="updatedDate";
      cfgdateField.type="hidden";
      cfgdateField.value=updatedate;
      form_ref.appendChild(cfgdateField);
  
      var cfgproductField = document.createElement("input");
      cfgproductField.name="productname";
      cfgproductField.type="hidden";
      cfgproductField.value=productname;
      form_ref.appendChild(cfgproductField);
  
      var cfgproductVersionField = document.createElement("input");
      cfgproductVersionField.name="productversion";
      cfgproductVersionField.type="hidden";
      cfgproductVersionField.value=productversion;
      form_ref.appendChild(cfgproductVersionField);
  
      var projectIdField = document.createElement("input");
      projectIdField.name="projectid";
      projectIdField.type="hidden";
      projectIdField.value=$("#projectId").val();
      form_ref.appendChild(projectIdField);
  
      var cfgprevPageField = document.createElement("input");
      cfgprevPageField.name="backpage";
      cfgprevPageField.type="hidden";
      cfgprevPageField.value=$("#backPage").val();
      form_ref.appendChild(cfgprevPageField);
  
      var hiddenEmailField = document.createElement("input");
      hiddenEmailField.setAttribute("type", "hidden");
      hiddenEmailField.setAttribute("name", "emailaddress");
      //hiddenEmailField.setAttribute("value", document.getElementById("usernamespan").innerHTML);
      hiddenEmailField.setAttribute("value", emailid);
      form_ref.appendChild(hiddenEmailField);
  
      var hiddenEmailField = document.createElement("input");
      hiddenEmailField.setAttribute("type", "hidden");
      hiddenEmailField.setAttribute("name", "fullemailid");
      hiddenEmailField.setAttribute("value", fullEmailId);
      form_ref.appendChild(hiddenEmailField);    
  
      var hiddenConvertedField = document.createElement("input");
      hiddenConvertedField.setAttribute("type", "hidden");
      hiddenConvertedField.setAttribute("name", "converted");
      hiddenConvertedField.setAttribute("value", converted);
      form_ref.appendChild(hiddenConvertedField);
  
      setTimeout(function(){
          form_ref.submit();
      }, 10);
  
  
  }
  </code></pre>