title: DataTables warning: table id=tblList - Requested unknown parameter. For more information about this error, please see http://datatables.net/tn/4
body: <p>C#</p>
  
  <pre><code>[WebMethod]
  public string loadLeaveRequests(int empID, int StatID, int isOwn)
  {
      List&lt;lstLeaveRequest&gt; mylist = new List&lt;lstLeaveRequest&gt;();
      using (SqlConnection connection = new SqlConnection(connectionString()))
      {
          connection.Open();
          SqlCommand cmd = new SqlCommand("spLoadLeaveRequest", connection);
          cmd.Parameters.Add("@empID", SqlDbType.Int).Value = empID;
          cmd.Parameters.Add("@Stat", SqlDbType.Int).Value = StatID;
          cmd.Parameters.Add("@Own", SqlDbType.Int).Value = isOwn;
          cmd.CommandType = CommandType.StoredProcedure;
          cmd.CommandTimeout = 0;
          SqlDataReader dr = cmd.ExecuteReader();
  
          while (dr.Read())
          {
              mylist.Add(new lstLeaveRequest
              {
                  reqID = dr["reqID"].ToString(),
                  dateFiled = dr["save_date"].ToString(),
                  fname = dr["first_name"].ToString(),
                  leaveType = dr["leaveAlias"].ToString(),
                  dateFrom = dr["DateFrom"].ToString(),
                  fromWhen = dr["FromWhen"].ToString(),
                  dateTo = dr["DateTo"].ToString(),
                  toWhen = dr["Towhen"].ToString(),
                  reason = dr["Reason"].ToString(),
                  remarks = dr["Remarks"].ToString(),
                  sStatus = dr["sStatus"].ToString(),
                  dateApprove = dr["approve_date"].ToString(),
                  totalDays = dr["totalDays"].ToString(),
                  grpID = dr["groupID"].ToString(),
              });
          }
          dr.Close();
          connection.Close();
      }
      JavaScriptSerializer jss = new JavaScriptSerializer();
      string jsn = jss.Serialize(mylist);
      return jsn;
  }
  </code></pre>
  
  <p>JavaScript</p>
  
  <pre><code>function loadLeaveRequest(isOwn) {
  
      if ($('#tblList').hasClass('dataTable')) {
          $('#tblList').dataTable().fnDestroy();
          $('#tblList').removeClass('dataTable');
      }
  
      var xdata = "{'empID':'" + STATUS.USER_ID   //sa pgfifilter ng group kailang grpID lang ang makuha sa DB
                  + "','StatID':'" + $('#cboStatus option:selected').val() //hindi na kailangan gumamit ng stored Procedure.
                  + "','isOwn':'" + isOwn                                     //gumawa ng CommandType.Text sa bagong SELECT Clause
              + "'}";
  
      $.ajax({
          type: 'POST',
          url: '../WebService/wsLeaveRequest.asmx/loadLeaveRequests',
          dataType: 'json',
          data: xdata,
          contentType: 'application/json; charset=utf-8',
          success: function (response) {
              $('#tbodyList').empty();
              var cells = eval("(" + response.d + ")");
              for (var i = 0; i &lt; cells.length; i++) {
  
                  var txtFromWhen;
                  var txtToWhen;
                  var disable = '';
  
                  if (cells[i].fromWhen == 2) {
                      txtFromWhen = "(AM)";
                  }
                  else if (cells[i].fromWhen == 3) {
                      txtFromWhen = "(PM)";
                  }
                  else {
                      txtFromWhen = "";
                  }
  
                  if (cells[i].toWhen == 2) {
                      txtToWhen = "(AM)";
                  }
                  else if (cells[i].fromWhen == 3) {
                      txtToWhen = "(PM)";
                  }
                  else {
                      txtToWhen = "";
                  }
  
  
                  var sStat; //Convertion of int to String
                  if (cells[i].sStatus == 1) {
                      sStat = "Approved";
                      disable = '';
                  }
                  else if (cells[i].sStatus == 2) {
                      sStat = "Denied";
                      disable = '';
                  }
                  else if (cells[i].sStatus == 3) {
                      sStat = "Cancelled";
                      disable = 'disabled'
                  }
                  else {
                      sStat = "Pending";
                      disable = '';
                  }
  
                  $('#tbodyList').append('&lt;tr&gt;'
                      + '&lt;td style="font-size:11px; text-align:center;"&gt;&lt;input type="checkbox" ' + disable + '&gt;&lt;/td&gt;'
                      + '&lt;td style="font-size:11px; text-align:center;"&gt;' + cells[i].reqID + '&lt;/td&gt;'
                      + '&lt;td style="font-size:11px; text-align:center;"&gt;' + cells[i].fname + '&lt;/td&gt;'
                      + '&lt;td style="font-size:11px; text-align:center;"&gt;' + cells[i].leaveType + '&lt;/td&gt;'
                      + '&lt;td style="font-size:11px; text-align:center;"&gt;' + cells[i].dateFrom.substring(0, 10) + txtFromWhen + '~' + '&lt;br&gt;' + cells[i].dateTo.substring(0, 10) + txtToWhen + '&lt;/td&gt;'
                      + '&lt;td style="font-size:11px; text-align:center;"&gt;' + cells[i].totalDays + '&lt;/td&gt;'
                      + '&lt;td style="font-size:11px; text-align:center; word-wrap: break-all;"&gt;' + cells[i].reason + '&lt;/td&gt;'
                      + '&lt;td style="font-size:11px; text-align:center; word-wrap: break-word;"&gt;' + cells[i].remarks + '&lt;/td&gt;'
                      + '&lt;td style="font-size:11px;"&gt;' + cells[i].dateFiled + '&lt;/td&gt;'
                      + '&lt;td style="font-size:11px; text-align:center;"&gt;' + sStat + '&lt;/td&gt;'
                      + '&lt;td style="font-size:11px; text-align:center;"&gt;' + cells[i].dateApprove + '&lt;/td&gt;'
                      + '&lt;td style="font-size:11px; text-align:center;"&gt;' + cells[i].grpID+ '&lt;/td&gt;'
  
                  + '&lt;/tr&gt;');
              }
          },
          error: function (error) {
              console.log(error);
          },
          complete: function () {
              $('#tblList').dataTable({
  
                  "order": [],
                  "destroy": true,
                  "columnDefs": [{
                      "targets": 'no-sort',
                      "orderable": false,
                  }]
              }).end();
              $('#tblList').css('width', '100%');
          }
      });
  }
  </code></pre>
  
  <p>HTML</p>
  
  <pre><code>&lt;table id="tblList" class="table border bordered hovered"&gt;
      &lt;thead&gt;
          &lt;tr&gt;
              &lt;td style="font-size:10px; text-align:center;"&gt;&lt;input type="checkbox" id="cbAll"/&gt;&lt;/td&gt;
              &lt;td style="font-size:10px; text-align:center;"&gt;Request No.&lt;/td&gt;
              &lt;td style="font-size:10px; text-align:center;"&gt;Employee&lt;/td&gt;                            
              &lt;td style="font-size:10px; text-align:center;"&gt;Leave Type&lt;/td&gt;
              &lt;!--&lt;td style="font-size:10px; text-align:center;" hidden&gt;Group ID&lt;/td&gt;--&gt;
              &lt;td style="font-size:10px; text-align:center;"&gt;Date of Leave&lt;/td&gt;
              &lt;td style="font-size:10px; text-align:center;"&gt;Total Days&lt;/td&gt;
              &lt;td style="font-size:10px; text-align:center;"&gt;Reason&lt;/td&gt;
              &lt;td style="font-size:10px; text-align:center;"&gt;Remarks&lt;/td&gt;
              &lt;td style="font-size:10px; text-align:center;"&gt;Date Filed&lt;/td&gt;
              &lt;td style="font-size:10px; text-align:center;"&gt;Status&lt;/td&gt;
              &lt;td style="font-size:10px; text-align:center;"&gt;Date Approved/Cancelled&lt;/td&gt;
  
          &lt;/tr&gt;
      &lt;/thead&gt;
      &lt;tbody id="tbodyList"&gt;
  
      &lt;/tbody&gt;
  &lt;/table&gt;
  </code></pre>
  
  <p>Stored Procedure </p>
  
  <pre><code>CREATE PROCEDURE [dbo].[spLoadLeaveRequest]
      @empID INT = 101, 
      @Stat INT = 99,
      @Own INT = 0
  AS
  BEGIN
  
      DECLARE @SqlStr VARCHAR(1000)
      DECLARE @SqlWhere VARCHAR(500)
  
      SET @SqlStr = 'select a.reqID, a.save_date, b.first_name, c.leaveAlias, d.groupID, CONVERT(VARCHAR(10),a.DateFrom,101) DateFrom, a.FromWhen, 
                      CONVERT(VARCHAR(10),a.DateTo,101) DateTo, a.ToWhen, a.totalDays, a.Reason,a.Remarks, a.sStatus, 
                      a.approve_date, a.sStatusAdmin,a.approve_dateAdmin
                  from tblLeaveRequest a 
                      join userinfo b on a.Save_User = b.empID
                      join tblLeaveType c on a.typeOfLeave=c.leaveID
                      join tblGroup d on b.groupNo = d.groupID
                  WHERE YEAR(a.save_date) = YEAR(GETDATE()) '
  
      IF (SELECT userType FROM userinfo WHERE empID = @empID) = 1
          BEGIN
              SET @SqlWhere = ' AND b.empID = ' + CAST(@empID AS VARCHAR) + '' 
          END
      ELSE IF (SELECT userType FROM userinfo WHERE empID = @empID) = 2
          BEGIN
              IF  @Own = 1
                  BEGIN
                      SET @SqlWhere = ' AND b.empID = ' + CAST(@empID AS VARCHAR) + '' 
                  END
              ELSE
                  BEGIN
                      SET @SqlWhere = ' AND b.groupNo = ' + CAST((SELECT groupNo FROM userinfo WHERE empID = @empID) AS VARCHAR) + ' AND b.empID &lt;&gt; ' + CAST(@empID AS VARCHAR) + '' 
                  END
          END
      ELSE IF (SELECT userType FROM userinfo WHERE empID = @empID) = 3
          BEGIN
              IF  @Own = 1
                  BEGIN
                      SET @SqlWhere = ' AND b.empID = ' + CAST(@empID AS VARCHAR) + '' 
                  END
              ELSE
                  BEGIN
                      SET @SqlWhere = ' AND b.empID &lt;&gt; ' + CAST(@empID AS VARCHAR) + '' 
                  END
          END
  
      IF @Stat = 99
          BEGIN
              SET @SqlWhere = @SqlWhere
          END
      ELSE
          BEGIN
              SET @SqlWhere = @SqlWhere + ' AND a.sStatus=' + CAST(@Stat AS VARCHAR) + '' 
          END
  
  
      EXEC(@SqlStr + @SqlWhere + ' ORDER BY a.reqID DESC')
  
  END
  </code></pre>
  
  <p>Can someone help me with this one. My code doesn't return all the values in the data table. </p>
  
  <p>can someone find the bug in my code? it has an output but not all the database fields was returned, the Last item "grpID" is not shown in the table.</p>
  
  <p>i know someone out there has a capability to solve this, so please help me guys Guys..</p>