usage/server-side is wrong: should be bServerSide but shows bProcessing
usage/server-side is wrong: should be bServerSide but shows bProcessing
jborrajo
Posts: 14Questions: 0Answers: 0
Hi,
First od all, thanks a lot for this great plugin.
My first try at serverside processing was failing untill I noticed (thanks to Fiddler) the plugin was using GET instead of POST request... anyway, the problem was the documentation (which is great except for this issue) says the option to enable server side processing is "bProcessing" which is wrong, the option is "bServerSide".
Please fix the documentation at http://www.datatables.net/usage/server-side, Initialisation parameters
Best regards
Javier
First od all, thanks a lot for this great plugin.
My first try at serverside processing was failing untill I noticed (thanks to Fiddler) the plugin was using GET instead of POST request... anyway, the problem was the documentation (which is great except for this issue) says the option to enable server side processing is "bProcessing" which is wrong, the option is "bServerSide".
Please fix the documentation at http://www.datatables.net/usage/server-side, Initialisation parameters
Best regards
Javier
This discussion has been closed.
Replies
Very good catch - thank you for that. The documentation has been fixed now.
Regards,
Allan
iSortDir_(int) has a misleading name... it starts with "i" so it suggests it is an int
but the actual value in my test is "asc" so the name should be sSortDir_(int)
Since the documentation does not specify the parameter type, the naming convention should be consistent.
I am using ASP.NET MVC and C# so the parameter datatype matters. I guess PHP does not fail on this issue, but C# does.
I really like this plugin. This little issues are costing me a little pain to get the server side scenario to work, though.
Best regards
Javier
Excellent point - one of the downsides to Hungarian notation... I've tried to be consistent - but slipped up here. Having said that, the variable name doesn't define the type in C# so iNumber can easily be a string - it's just a bit annoying when using it.
Annoyingly this is incorrect in the code as well, and a correction would break backwards compatibility for those using 1.5.x at the moment. This is one of those really frustrating bugs, with three options that I can see:
1. Add sSortDir_(int) as it should have been and leave iSortDir_(int)
2. Add sSortDir_(int) but remove iSortDir_(int) - breaks old scripts but reduces the length of the GET query
3. Leave it as it is
I don't fancy the idea of sending the same information on the GET parameters twice, and I don't want to break backwards compatibility in a bugfix release, so I fear that this is one which will be in there until 1.6.x for whenever that happens...
Regards,
Allan
Totally agree, please use option 3. leave as it is.
In my case the issue would not have happened if the documentation had included an example of typical values.
Something like:
iSortDir_(int) - Direction to be sorted, for example "asc"
I just got the server side POST scenario to work with ASP.NET MVC and C#.
Had to do a few edits in the Javascript code to deal with a couple more issues.
Please see other threads I have created.
I really like this plugin. DataTables rocks!!
Regards
Javier
I've added a bit more information to the page, including an example of what to expect (where appreciate): http://datatables.net/usage/server-side
Thanks!
Allan
Thank you very much for your support.
Please forgive me if I am being a little tyresome here, just another one:
string: sEcho - Information for DataTables to use for rendering
I think sEcho is an int, since the values I am seeing are like 1 ... and the jquery.DataTables.js code looks like:
[code]
oSettings.iServerDraw = json.sEcho * 1;
[/code]
Anyway, I now got the server side C# code right. Please note the parameter list must have valid types, such as int or string where appropiate.
This is the ASP.NET MVC action method, complete with LINQ. Please notice how the query is counted 3 times.
I think it looks nice :-)
[code]
public JsonResult PageFilterSort(
/* paging */ int iDisplayStart, int iDisplayLength
/* filtering */, string sSearch, bool bEscapeRegex
/* not used */ , int iColumns
/* sorting */, int iSortingCols, int iSortCol_0, string iSortDir_0
, int sEcho
)
{
JsonResult res = null;
// LINQ query
var query = (from x in mEmpleadoGNRepository.EmpleadoGNs
select x);
// iTotalRecords count #1 all records in the table
int total = query.Count();
//
#region [ IF filtering ]
if ( !string.IsNullOrEmpty(sSearch) ) {
query = (from x in query
where (x.Nombre.Contains(sSearch)
|| x.Apellidos.Contains(sSearch)
|| x.Email.Contains(sSearch)
|| x.Cargo.Contains(sSearch)
|| x.Departamento.Contains(sSearch)
|| x.Movil.Contains(sSearch)
|| x.Telefono.Contains(sSearch)
) select x);
}
#endregion
//
#region [ IF sorting ]
if (iSortingCols > 0)
{
bool basc = (iSortDir_0 == "asc");
switch (iSortCol_0)
{
case 1:
query = basc ?
query.OrderBy(x => x.Departamento)
: query.OrderByDescending(x => x.Departamento);
break;
case 2:
query = basc ?
query.OrderBy(x => x.Cargo)
: query.OrderByDescending(x => x.Cargo);
break;
case 3:
query = basc ?
query.OrderBy(x => x.Nombre)
: query.OrderByDescending(x => x.Nombre);
break;
case 4:
query = basc ?
query.OrderBy(x => x.Apellidos)
: query.OrderByDescending(x => x.Apellidos);
break;
default:
query = basc ?
query.OrderBy(x => x.Nombre)
: query.OrderByDescending(x => x.Nombre);
break;
}
}
#endregion
//
// iTotalDisplayRecords count #2 all filtered records
int totaldisp = query.Count();
//
#region [ IF paging ]
if ( iDisplayLength > 0 ) {
query = query.Skip(iDisplayStart).Take(iDisplayLength);
}
#endregion
//
#region [ Result ]
List ls = query.ToList();
object[] aa = new object[ls.Count]; // count #3 paged records
int i = 0;
foreach (EmpleadoGN emp in ls)
{
aa[i++] = emp.getRowData();
}
var o = new {
sEcho = sEcho,
iTotalRecords = total,
iTotalDisplayRecords = totaldisp,
aaData = aa
};
res = Json(o);
#endregion
//
return res;
}
}
[/code]
HTH, regards
Javier
Re sEcho: Actually this was intentional - you are right that at the moment sEcho contains only an integer, however, this may very well change in the future, should DataTables ever need any more stateful information to be returned from the server-side. So it was forward looking variable naming that one. Also sEcho should be unaltered by the server-side process, so treating it as a string will help ensure that this is the case (since it might become a "true" string in future treating it as an integer could be dangerous).
Re your C# script: Awesome! Thanks for sharing that with us :-)
Regards,
Allan
C# 3 is really something... and LINQ ... and ASP.NET MVC ...
I used to love Java programming a few years back but now I am totally set on .NET
Best regards
Javier
Yup - I've been using C# quite a bit recently, and think it's a superb language to code in. Kudos to Microsoft for producing it.
Allan
I've been looking at this thread and I am also using c# and ASP.NET MVC. However I am having troubles getting the data to load into the table. I am trinyg a very simple example but it keeps coming back saying "Microsoft JScript error: 'undefined' is null or not an object" from the jquery.datatable.min.js file
It happens on line 440 which is [code]{var aColumns=sColumns.split(",")[/code]
My controller is
[code]
public JsonResult Json()
{
JsonResult res = null;
object[] aa = new object[1];
Reps reps = new Reps();
reps.Name = "John";
reps.Job = "Plumber";
aa[0] = reps;
var o = new
{
sEcho = 1,
iTotalRecords = 1,
iTotalDisplayRecords = 1,
aaData = aa
};
res = Json(o);
return res;
}
[/code]
my jquery file is
[code]
var oTable;
$(document).ready(function() {
//event handlers
$("#uxAddReferral").click(OnAddReferralClick);
$('#demo').html('');
//setup the grid
oTable = $('#uxReferralTable').dataTable(
{
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": "/Referral/Json"
}
);
});
[/code]
html file is (actually .spark)
[code]
[/code]
any ideas??
This looks like a double post - there is no need to do that, the community tried to answer all threads in the forum. Please refer to the thread that you have created: http://datatables.net/forums/comments.php?DiscussionID=818
Allan
I was having a similar issue trying to use server-side processing in ASP.NET MVC2. Using FireBug, I noticed what I will define as a bug in JavaScript. My GetData() controller action method was defined just like the example shown above from jborrajo. My GetData() action method was never being called, and DataTables was stuck displaying the "Processing" message. In FireBug, even though the call appeared to be successful, clicking on the HTML section revealed an error:
Server Error in '/' Application.
The parameters dictionary contains a null entry for parameter 'bEscapeRegex' of non-nullable type 'System.Boolean' for method 'System.Web.Mvc.JsonResult GetData(Int32, Int32, System.String, Boolean, Int32, Int32, Int32, System.String, System.String)' in 'mvcEstimate.Controllers.MachineController'. An optional parameter must be a reference type, a nullable type, or be declared as an optional parameter.
Parameter name: parameters
Apparently, JavaScript was passing a null value in for bEscapeRegex, which is defined as a boolean and does not allow null values. Changing the definition to "bool? bEscapeRegex" solved the problem!