如何在 jtable jquery 插件中获取当前排序标准
How to get current sort criteria in jtable jquery plugin
我在 asp.net mvc web 应用程序中使用 Jtable Jquery plugin 进行 CRUD 操作。这可以正常工作,但在某些功能中,我需要当前的网格排序标准。因此,我阅读了它的文档,但没有找到任何方法或事件来在我的 jquery 代码中获取当前的网格排序标准。当页面加载或排序列 link 被点击时,排序标准通过 ajax 调用发送到控制器以进行处理并获取数据以绑定到网格。我可以在服务器端获取它,但我希望它在 jquery 的客户端中使用它,但不知道如何获取它。对此的任何解决方案都非常有帮助..
谢谢....
Javascript
sorting: true, //Enable sorting
defaultSorting: 'Name ASC', //Sort by Name by default
控制器
[HttpPost]
public JsonResult PersonList(int jtStartIndex = 0, int jtPageSize = 0, string jtSorting = null)
{
try
{
int personCount = _personRepository.GetPersonCount();
List<person> persons = _personRepository.GetPersons(jtStartIndex, jtPageSize, jtSorting);
return Json(new { Result = "OK", Records = persons, TotalRecordCount = personCount });
}
catch (Exception ex)
{
return Json(new { Result = "ERROR", Message = ex.Message });
}
}
带排序条件的 GetPersons 方法
public IEnumerable GetDeployments(string show, string name, int startIndex, int count, string sorting)
{
//Get List of Persons from Database
if (!string.IsNullOrEmpty(name))
{
deploymentsList = deploymentsList.Where(p => p.KomponentenName.ToString().StartsWith(name));
}
if (string.IsNullOrEmpty(sorting) || sorting.Equals("KomponentenName ASC"))
{
deploymentsList = deploymentsList.OrderBy(p => p.KomponentenName);
}
else if (sorting.Equals("KomponentenName DESC"))
{
deploymentsList = deploymentsList.OrderByDescending(p => p.KomponentenName);
}
else if (sorting.Equals("datum ASC"))
{
deploymentsList = deploymentsList.OrderBy(p => p.datum);
}
else if (sorting.Equals("datum DESC"))
{
deploymentsList = deploymentsList.OrderByDescending(p => p.datum);
}
else if (sorting.Equals("RequesterName ASC"))
{
deploymentsList = deploymentsList.OrderBy(p => p.RequesterName);
}
else if (sorting.Equals("RequesterName DESC"))
{
deploymentsList = deploymentsList.OrderByDescending(p => p.RequesterName);
}
else if (sorting.Equals("dateDeployed ASC"))
{
deploymentsList = deploymentsList.OrderBy(p => p.dateDeployed);
}
else if (sorting.Equals("dateDeployed DESC"))
{
deploymentsList = deploymentsList.OrderByDescending(p => p.dateDeployed);
}
else
{
deploymentsList = deploymentsList.OrderBy(p => p.KomponentenName); //Default!
}
return count > 0
? deploymentsList.Skip(startIndex).Take(count).ToList() //Paging
: deploymentsList.ToList(); //No paging
}
由于您想在客户端 javascript 代码中获取排序标准值,您可以通过标准 jQuery 扩展过程扩展 jQuery jTable 来实现此目的。然后一旦你在你的扩展代码中,你可以写:
this._lastSorting
以上会给你:
ObjectfieldName: "size"
sortOrder: "ASC"
如果您需要有关如何扩展 jTable 的信息,可以查看 this 关于如何扩展 jQuery 插件的问题。
希望对您有所帮助。
我在 asp.net mvc web 应用程序中使用 Jtable Jquery plugin 进行 CRUD 操作。这可以正常工作,但在某些功能中,我需要当前的网格排序标准。因此,我阅读了它的文档,但没有找到任何方法或事件来在我的 jquery 代码中获取当前的网格排序标准。当页面加载或排序列 link 被点击时,排序标准通过 ajax 调用发送到控制器以进行处理并获取数据以绑定到网格。我可以在服务器端获取它,但我希望它在 jquery 的客户端中使用它,但不知道如何获取它。对此的任何解决方案都非常有帮助..
谢谢....
Javascript
sorting: true, //Enable sorting
defaultSorting: 'Name ASC', //Sort by Name by default
控制器
[HttpPost]
public JsonResult PersonList(int jtStartIndex = 0, int jtPageSize = 0, string jtSorting = null)
{
try
{
int personCount = _personRepository.GetPersonCount();
List<person> persons = _personRepository.GetPersons(jtStartIndex, jtPageSize, jtSorting);
return Json(new { Result = "OK", Records = persons, TotalRecordCount = personCount });
}
catch (Exception ex)
{
return Json(new { Result = "ERROR", Message = ex.Message });
}
}
带排序条件的 GetPersons 方法
public IEnumerable GetDeployments(string show, string name, int startIndex, int count, string sorting)
{
//Get List of Persons from Database
if (!string.IsNullOrEmpty(name))
{
deploymentsList = deploymentsList.Where(p => p.KomponentenName.ToString().StartsWith(name));
}
if (string.IsNullOrEmpty(sorting) || sorting.Equals("KomponentenName ASC"))
{
deploymentsList = deploymentsList.OrderBy(p => p.KomponentenName);
}
else if (sorting.Equals("KomponentenName DESC"))
{
deploymentsList = deploymentsList.OrderByDescending(p => p.KomponentenName);
}
else if (sorting.Equals("datum ASC"))
{
deploymentsList = deploymentsList.OrderBy(p => p.datum);
}
else if (sorting.Equals("datum DESC"))
{
deploymentsList = deploymentsList.OrderByDescending(p => p.datum);
}
else if (sorting.Equals("RequesterName ASC"))
{
deploymentsList = deploymentsList.OrderBy(p => p.RequesterName);
}
else if (sorting.Equals("RequesterName DESC"))
{
deploymentsList = deploymentsList.OrderByDescending(p => p.RequesterName);
}
else if (sorting.Equals("dateDeployed ASC"))
{
deploymentsList = deploymentsList.OrderBy(p => p.dateDeployed);
}
else if (sorting.Equals("dateDeployed DESC"))
{
deploymentsList = deploymentsList.OrderByDescending(p => p.dateDeployed);
}
else
{
deploymentsList = deploymentsList.OrderBy(p => p.KomponentenName); //Default!
}
return count > 0
? deploymentsList.Skip(startIndex).Take(count).ToList() //Paging
: deploymentsList.ToList(); //No paging
}
由于您想在客户端 javascript 代码中获取排序标准值,您可以通过标准 jQuery 扩展过程扩展 jQuery jTable 来实现此目的。然后一旦你在你的扩展代码中,你可以写:
this._lastSorting
以上会给你:
ObjectfieldName: "size"
sortOrder: "ASC"
如果您需要有关如何扩展 jTable 的信息,可以查看 this 关于如何扩展 jQuery 插件的问题。
希望对您有所帮助。