Please help on java script error.
Please help on java script error.
gsurge
Posts: 5Questions: 0Answers: 0
I am getting the error "DataTables warning (table id = 'searchResults'): Requested unknown parameter '1' from the data source for row 0"
when the Data-table doesn't have any record to display.
here is part of the script:
$(document).ready(function() {
$('#searchResults').dataTable({
"aoColumnDefs": [
{ "sType": "date", "aTargets": [3] },
{ "sType": "html", "aTargets": [4] },
{ "sClass": "centered-alignment", "aTargets": ["_all"] }
],
"aaSorting": [[3, 'desc']],
"sPaginationType": "full_numbers"
});
});
....
@Html.Grid(Model.Transactions).Columns(column => {
column.For(t => t.BusinessEntityName);
column.For(t => t.SccId).Named("XX ID");
column.For(t => t.DisplayType).Named("Type");
column.For(t => t.Date);
column.For(x => Html.Partial("_TransactionLink", x)).Named("Confirmation Number / DCN");
}).Attributes(id => "searchResults")
help please.
when the Data-table doesn't have any record to display.
here is part of the script:
$(document).ready(function() {
$('#searchResults').dataTable({
"aoColumnDefs": [
{ "sType": "date", "aTargets": [3] },
{ "sType": "html", "aTargets": [4] },
{ "sClass": "centered-alignment", "aTargets": ["_all"] }
],
"aaSorting": [[3, 'desc']],
"sPaginationType": "full_numbers"
});
});
....
@Html.Grid(Model.Transactions).Columns(column => {
column.For(t => t.BusinessEntityName);
column.For(t => t.SccId).Named("XX ID");
column.For(t => t.DisplayType).Named("Type");
column.For(t => t.Date);
column.For(x => Html.Partial("_TransactionLink", x)).Named("Confirmation Number / DCN");
}).Attributes(id => "searchResults")
help please.
This discussion has been closed.
Replies
Allan
Allan
.chtml:
@using MvcContrib.UI.Grid
@using Web.UI.Areas.Accounts.Models
@model UserTransactionsViewModel
@{
ViewBag.Title = "User Transactions History";
}
@section TitleContent {
User Transaction History
}
@section titleTextContent{
User Transaction History
}
@section ScreenIdContent{
e1200
}
#searchResults
{
width: 100%;
float: left;
}
#container
{
width: 600px;
}
#UserInfo
{
margin-top: 2em;
margin-bottom: 2em;
}
.centered-alignment {
text-align: center;
}
$(document).ready(function () {
$('#searchResults').dataTable({
"aoColumnDefs": [
{ "sType": "date", "aTargets": [3] },
{ "sType": "html", "aTargets": [4] },
{ "sClass": "centered-alignment", "aTargets": ["_all"]}
],
"aaSorting": [[3, 'desc']],
"sPaginationType": "full_numbers"
});
});
@Html.Grid(Model.Transactions).Columns(column => {
column.For(t => t.BusinessEntityName);
column.For(t => t.Id).Named("ID");
column.For(t => t.DisplayType).Named("Type");
column.For(t => t.Date);
column.For(x => Html.Partial("_TransactionLink", x)).Named("Confirmation Number / DCN");
}).Attributes(id => "searchResults")
---------------------------------------------------------------------------
model:
using System.Collections.Generic;
using Web.UI.Dtos;
namespace Web.UI.Areas.Accounts.Models
{
public class UserTransactionsViewModel
{
public IList Transactions { get; set; }
}
}
---------------------------------------------------------------------------------
controller:
using System.Linq;
using System.Web.Mvc;
using Core;
using Core.BusinessEntities;
using NHibernate;
using NHibernate.Linq;
using Web.UI.Areas.Accounts.Models;
using Web.UI.Dtos;
using Web.UI.Helpers;
namespace Web.UI.Areas.Accounts.Controllers
{
[Authorize]
public class HistoryController : BaseController
{
private readonly ISession _session;
private readonly IProvideUserContext _userContext;
public HistoryController(ISession session, IProvideUserContext userContext)
{
_session = session;
_userContext = userContext;
}
public ActionResult Transactions()
{
var transactions = (from t in _session.Query().Where(x => x.UserId == _userContext.CurrentUserId).ToList()
select new TransactionHistoryDto
{
BusinessEntityName = t.EntityName,
Id = t.Id,
DisplayType = t.DisplayType,
Type = t.Type,
Date = t.TransactionDate,
ConfirmationNumber = t.DCN == null ? t.ArNumber.ToString() : t.DCN.ToString()
}).OrderByDescending(x => x.Date);
var model = new UserTransactionsViewModel
{
Transactions = transactions.ToList()
};
return View(model);
}
}
}
-------------------------------
when i click on transaction history link i found the error :
"DataTables warning (table id = 'searchResults'): Requested unknown parameter '1' from the data source for row 0"
Allan
$(document).ready(function () {
$('#searchResults').dataTable({
"aoColumnDefs": [
{ "sType": "date", "aTargets": [3] },
{ "sType": "html", "aTargets": [4] },
{ "sClass": "centered-alignment", "aTargets": ["_all"]}
],
"aaSorting": [[3, 'desc']],
"sPaginationType": "full_numbers"
});
});
There is no data available.
...
this code has solved the problem:
$(document).ready(function () {
if (!$('#searchResults tr td:first').html().match('There is no data available')) {
$('#searchResults').dataTable({
"aoColumnDefs": [
{ "sType": "date", "aTargets": [3] },
{ "sType": "html", "aTargets": [4] },
{ "sClass": "centered-alignment", "aTargets": ["_all"] }
],
"aaSorting": [[3, 'desc']],
"sPaginationType": "full_numbers"
});
} else {
$('#searchResults td').addClass('centered-alignment');
}
});
Thank you so much for your time.