Select list column filter, global filter server-side question
Select list column filter, global filter server-side question
Ironwil616
Posts: 50Questions: 0Answers: 0
I have the server-side paging and sorting working correctly, as well as the global filter. Three of the columns in my table have select list filters which aren't working. They trigger the call to the server method, but the value for iSortingCols is zero every time, as is the value for iSortCol_0. Here's a bit of my server code (C#):
[code]
string sEcho = formCollection["sEcho"];
int totalRecords = projects.Count();
int totalDisplayRecords = 0; // Total records after filters are applied
int displayStart = formCollection["iDisplayStart"].ToInt(); // Skip
int displayLength = formCollection["iDisplayLength"].ToInt(); // Take
int sortingCols = formCollection["iSortingCols"].ToInt();
int sortColIndex = formCollection["iSortCol_0"].ToInt();
string sortDirection = formCollection["sSortDir_0"];
string globalSearch = formCollection["sSearch"];
[/code]
Short aside - For those familiar with C#, the "ToInt()" method is an extension I wrote to simplify casting a string to an integer. I write extension methods for any irritatingly redundant code. The method looks like this:
[code]
// If a default return value of zero isn't ideal, this ain't the method to use!
public static int ToInt(this string source)
{
int result;
if (int.TryParse(source, out result)) return result;
return 0;
}
[/code]
Back to the topic - I set the select lists from server code in a page model like this:
[code]
<%: Html.DropDownList("Type", Model.TypeList, new { @class = "inputMedium dropdownfilter" })%>
[/code]
This is the ASP.NET MVC 2 View Engine code, but basically it just takes the select list values from the server code and creates a regular select list. I wired them up like so:
[code]
$('.dropdownfilter', this).change( function () {
// Get 'th' element holding the input element.
var th = $(this).parent();
// Get 'tr' element holding the 'th' element.
var tr = $(this).parents("tr");
var index = tr.children().index(th);
oTable.fnFilter( $(this).val(), index );
} );
[/code]
I did it this way because I don't have select list filters for each column, and need the correct index assigned to each. Anyway, after selecting a value from one of the select lists, I my server-side method executes, but there's a zero value in both iSortingCols and iSortCol_0. Is there a different way to access filter values for select lists than for text input? I had the text input working, but was asked to provide select lists for certain columns, and also I couldn't get the fnSetFilteringDelay to work with the text input column filters, making them pretty much useless. I read posts on this but no apparent fix.
Besides the above issue, when using the sSearch global filter, both the fnSetFilteringDelay function and the server variable are working just fine. The problem I have is with the sSortDir_0 value, which is null. Since my server query re-runs the sorting and paging logic every time the user interacts with the page, this is a real problem.
Any advice?
[code]
string sEcho = formCollection["sEcho"];
int totalRecords = projects.Count();
int totalDisplayRecords = 0; // Total records after filters are applied
int displayStart = formCollection["iDisplayStart"].ToInt(); // Skip
int displayLength = formCollection["iDisplayLength"].ToInt(); // Take
int sortingCols = formCollection["iSortingCols"].ToInt();
int sortColIndex = formCollection["iSortCol_0"].ToInt();
string sortDirection = formCollection["sSortDir_0"];
string globalSearch = formCollection["sSearch"];
[/code]
Short aside - For those familiar with C#, the "ToInt()" method is an extension I wrote to simplify casting a string to an integer. I write extension methods for any irritatingly redundant code. The method looks like this:
[code]
// If a default return value of zero isn't ideal, this ain't the method to use!
public static int ToInt(this string source)
{
int result;
if (int.TryParse(source, out result)) return result;
return 0;
}
[/code]
Back to the topic - I set the select lists from server code in a page model like this:
[code]
<%: Html.DropDownList("Type", Model.TypeList, new { @class = "inputMedium dropdownfilter" })%>
[/code]
This is the ASP.NET MVC 2 View Engine code, but basically it just takes the select list values from the server code and creates a regular select list. I wired them up like so:
[code]
$('.dropdownfilter', this).change( function () {
// Get 'th' element holding the input element.
var th = $(this).parent();
// Get 'tr' element holding the 'th' element.
var tr = $(this).parents("tr");
var index = tr.children().index(th);
oTable.fnFilter( $(this).val(), index );
} );
[/code]
I did it this way because I don't have select list filters for each column, and need the correct index assigned to each. Anyway, after selecting a value from one of the select lists, I my server-side method executes, but there's a zero value in both iSortingCols and iSortCol_0. Is there a different way to access filter values for select lists than for text input? I had the text input working, but was asked to provide select lists for certain columns, and also I couldn't get the fnSetFilteringDelay to work with the text input column filters, making them pretty much useless. I read posts on this but no apparent fix.
Besides the above issue, when using the sSearch global filter, both the fnSetFilteringDelay function and the server variable are working just fine. The problem I have is with the sSortDir_0 value, which is null. Since my server query re-runs the sorting and paging logic every time the user interacts with the page, this is a real problem.
Any advice?
This discussion has been closed.