Reputation: 6438
I am working on a simple grid in ASP.NET using jTable (www.jTable.org). It's a page with a list of 'Residents', where there's a field called 'FacilityFrom' populated from a FACILITY table in the database. On the 'Residents' jTable I have a field that is using the 'options' attribute and pulling from the 'Facility' SQL table. I just want a drop down list where the first & default value is '(NONE)' when you go to add a new record.
I did some MSSQL magic and creating a record representing a default value (its field in the database is literally '(NONE)'. Then when populating the drop down I do
select FacilityID,Name from FACILITY where Name = '(NONE)'
UNION
select FacilityID,Name from FACILITY where Name <> '(NONE)'
I realize it's ugly (I put the necessary unique constraint to make it air-tight), but the query works as expected and puts the '(NONE)' option at the top; but for whatever reason, the jTable is doing some sorting magic on its own and putting it at the bottom! Even if I reverse the above select statements, still, it's at the bottom? Even if I put a breakpoint in the WebMethod called GetFacilityOptions - it's clear that the result is what I want it to be- (NONE) is always at index 0 in the list.. It seems something in jquery binding is making the change?
Anyway, I found the defaultValue attribute on the jTable documentation and thought it would solve my problem, but still it has no affect? The HTML is below:
FacilityFromID: {
title: 'Facility',
options: '/Residents.aspx/GetFacilityOptions',
defaultValue: '(NONE)'
},
The code-behind is:
[WebMethod(EnableSession = true)]
public static object GetFacilityOptions()
{
try
{
var facilities = BusinessObjects.DataAcesss.GetAllFacilities().Select(c => new { DisplayText = c.Name, Value = c.FacilityID });
//BREAKPOINT SAYS '(NONE)' IS AT INDEX 0 HERE!!
return new { Result = "OK", Options = facilities };
}
catch (Exception ex)
{
return new { Result = "ERROR", Message = ex.Message };
}
}
Anyone have any ideas/suggestions? Thanks so much!
Upvotes: 0
Views: 3675
Reputation: 11
, min_id: {
title: field name,
options: the options function,
defaultValue: $('#<% = ddlMin.ClientID %>').val() // where ddlMin.ClientID the value required
}
Upvotes: 1