I have three datatables on a page, two of which have left joins and have a pull-down field. One, the options are getting created correctly. The other one, no options array is created:
This one works:
public class LineItemsController : ApiController
{
[Route("api/LineItems")]
[HttpGet]
[HttpPost]
public IHttpActionResult LineItems()
{
var request = HttpContext.Current.Request;
var settings = Properties.Settings.Default;
using (var db = new Database(settings.DbType, settings.DbConnection))
{
var response = new Editor(db, "InvoiceStructure_LineItems", "LineItemID")
.Model<LineItemsModel>("InvoiceStructure_LineItems")
.Model<LineItemCategoryModel>("InvoiceStructure_Categories")
.Field(new Field("InvoiceStructure_LineItems.LineItemID"))
.Field(new Field("InvoiceStructure_LineItems.LineItem")
.Validator(Validation.NotEmpty())
)
.Field(new Field("InvoiceStructure_LineItems.CategoryID")
.Validator(Validation.NotEmpty())
.Validator(Validation.Numeric())
.Options("InvoiceStructure_Categories","CategoryID","Category")
)
.Field(new Field("InvoiceStructure_LineItems.sortby")
.Validator(Validation.NotEmpty())
)
.LeftJoin("InvoiceStructure_Categories", "InvoiceStructure_LineItems.CategoryID", "=", "InvoiceStructure_Categories.CategoryID")
.Where("InvoiceStructure_LineItems.CategoryID", request.Form["InvoiceStructure_LineItems.CategoryID"])
.Process(request)
.Data();
return Json(response);
}
}
}
correctly returns:
{draw: null,…}
draw: null
data: [{DT_RowId: "row_12",…}, {DT_RowId: "row_13",…}, {DT_RowId: "row_14",…}, {DT_RowId: "row_15",…},…]
0: {DT_RowId: "row_12",…}
1: {DT_RowId: "row_13",…}
2: {DT_RowId: "row_14",…}
3: {DT_RowId: "row_15",…}
4: {DT_RowId: "row_16",…}
DT_RowId: "row_16"
InvoiceStructure_LineItems: {LineItemID: 16, LineItem: "GIS Direct", CategoryID: "3", sortby: "5"}
LineItemID: 16
LineItem: "GIS Direct"
CategoryID: "3"
sortby: "5"
InvoiceStructure_Categories: {CategoryID: 3, category: "Direct Charges (Variable Costs)", sortby: "3"}
CategoryID: 3
category: "Direct Charges (Variable Costs)"
sortby: "3"
5: {DT_RowId: "row_17",…}
recordsTotal: null
recordsFiltered: null
error: null
fieldErrors: []
id: null
meta: {}
options: {InvoiceStructure_LineItems.CategoryID: [{value: 2, label: "Direct Charges (Fixed Costs)"},…]}
InvoiceStructure_LineItems.CategoryID: [{value: 2, label: "Direct Charges (Fixed Costs)"},…]
0: {value: 2, label: "Direct Charges (Fixed Costs)"}
1: {value: 3, label: "Direct Charges (Variable Costs)"}
2: {value: 1, label: "Indirect Charges"}
3: {value: 4, label: "Project Charges"}
4: {value: 5, label: "Telecom - Phone lines"}
5: {value: 7, label: "Telecom - Purchase / Labor Charges"}
6: {value: 6, label: "Telecom - Recurring Charges"}
files: {}
upload: {id: null}
debug: null
cancelled: []
This one does not
public class BillingSetup_UnitRatesController : ApiController
{
[Route("api/BillingSetup_UnitRates")]
[HttpGet]
[HttpPost]
public IHttpActionResult BillingSetup_UnitRates()
{
var request = HttpContext.Current.Request;
var settings = Properties.Settings.Default;
using (var db = new Database(settings.DbType, settings.DbConnection))
{
var response = new Editor(db, "BillingSetup_UnitRates", "UnitRateID")
.Model<BillingSetup_UnitRatesModel>("BillingSetup_UnitRates")
.Model<LineItemsModel>("InvoiceStructure_LineItems")
.Field(new Field("BillingSetup_UnitRates.effectivedate"))
.Field(new Field("BillingSetup_UnitRates.expiredate"))
.Field(new Field("BillingSetup_UnitRates.unitrate"))
.Field(new Field("BillingSetup_UnitRates.LineItemID")
.Validator(Validation.NotEmpty())
.Validator(Validation.Numeric())
.Options("InvoiceStructure_LineItems","LineItemID","LineItem")
)
.LeftJoin("InvoiceStructure_LineItems", "InvoiceStructure_LineItems.LineItemID", "=", "BillingSetup_UnitRates.LineItemID")
.Where("BillingSetup_UnitRates.LineItemID", request.Form["BillingSetup_UnitRates.LineItemID"])
.Process(request)
.Data();
return Json(response);
}
}
}
returns no options
{draw: null, data: [{DT_RowId: "row_3",…}], recordsTotal: null, recordsFiltered: null, error: null,…}
draw: null
data: [{DT_RowId: "row_3",…}]
0: {DT_RowId: "row_3",…}
DT_RowId: "row_3"
BillingSetup_UnitRates: {LineItemID: "16", effectivedate: "7/1/2012 12:00:00 AM", expiredate: null, unitrate: "307.41"}
LineItemID: "16"
effectivedate: "7/1/2012 12:00:00 AM"
expiredate: null
unitrate: "307.41"
InvoiceStructure_LineItems: {LineItemID: 16, LineItem: "GIS Direct", CategoryID: "3", sortby: "5"}
LineItemID: 16
LineItem: "GIS Direct"
CategoryID: "3"
sortby: "5"
recordsTotal: null
recordsFiltered: null
error: null
fieldErrors: []
id: null
meta: {}
options: {}
files: {}
upload: {id: null}
debug: null
cancelled: []