Working with array of values in editor
Working with array of values in editor
Hi
I have a need to modify the label of checkboxes on an editor form. The field names are shown on the editor as per the server code under the MJOIN (field "ListName") but on the form the wording needs to be different as the pricelist names are followed by a space, a dash, a space and some text based on the value of PriceListLevel. The problem I have is the 'data: function' js code is not hit when creating a new row, only when opening an existing row and I'm trying to get the right syntax for iterating values in the CustomerVoiceCLIPriceLists0 array. Thank you.
JS:
ajax: {
...
},
table: '#tblDataTable',
template: '#EditorForm',
fields: [
{
label: '@(lblo.lblLists):',
name: 'CustomerVoiceCLIPriceLists0[].id',
type: "checkbox",
data: function (row, type, val) {
if (row != null) {
$.each(row.CustomerVoiceCLIPriceLists0, function (i, e) {
if (e.PriceListType == 0) //voice sales price lists
{
if (e.PriceListLevel == 0)
{
return e.PriceList + ' - @(lblo.lblBaseList)';
}
else
{
return e.PriceList + ' - @(Model.ContactNumber)';
}
}
});
}
}
}
],
i18n: {...}
});
Server:
using (Database db = new Database(SetGetDbType2, SetGetDbConnection))
{
editor = new Editor(db, "CustomerVoiceCLI", "CustomerVoiceCLI.id")
.Model<CustomerSNsDBModel.CustomerVoiceCLI>("CustomerVoiceCLI");
editor.Field(new Field("CustomerVoiceCLI.id")
.Set(false)
);
editor.MJoin(new MJoin("CustomerVoiceCLIPriceLists")
.Name("CustomerVoiceCLIPriceLists0")
.Link("CustomerVoiceCLI.CustID", "CustomerVoiceCLIPriceLists.CustomerIndex")
.Link("CustomerVoiceCLI.id", "CustomerVoiceCLIPriceLists.CustomerVoiceCLIIndex")
.Model<CustomerSNsDBModel.CustomerVoiceCLIPriceLists>()
.Order("CustomerVoiceCLIPriceLists.CustomerVoiceCLIIndex ASC")
.Where(q =>
q.Where("CustomerVoiceCLIPriceLists.PriceListType", 0) //PriceListType indicates sales or purchase price list
)
.Field(new Field("id")
.Options(new Options()
.Table("GlobalPriceLists")
.Value("id")
.Label("ListName")
.Where(q =>
q.Where("GlobalPriceLists.ListType", 0) //ListType indicates voice or serv list
)
.Where(q =>
q.Where("GlobalPriceLists.ListInDB", 1)
)
.Where(q =>
q.Where("GlobalPriceLists.CustomerIndex", 0)
)
.Where(q =>
q.Where("GlobalPriceLists.CustomerIndex", lngContIdx)
)
)
.Set(false)
)
.Set(false)
);
editor.PostRemove += (sender, e) => t = Task.Run(() => Delete(intContTpe, lngContIdx, lngItemIdx)); //delete sn
editor.Debug(true);
editor.Process(formData);
}
Edited by Colin - Syntax highlighting. Details on how to highlight code using markdown can be found in this guide.
Answers
Treating the data as an array and modifying the values of its elements does not change what is displayed in the editor. I use 'data: function (row, type, val) {' else and it works but not here. Am I missing something? Thanks.
Should read:
I use:
'data: function (row, type, val) {'
elsewhere where there is no array of values and it works but not here.
I'd actually very much encourage you not to use the
fields.data
option as a function. It is possible, but you need to handle the set code as well.If all you need to do is modify the text shown for the checkbox label, use the
Label
method of theOptions
class on the server-side which is designed for exactly this sort of thing.Allan
Shoudl add that all buttons on the datatable point to the editor:
That's fine. I still think the server-side
Options
label rendering will be the way to do this. Did you give that a go?Allan
Hi Allan
I'm trying but am not sure how to use the Render method (I think that's what I have to use). Here's the code I have in server:
I have to show the ListName differently based on the Where clause:
If GlobalPriceLists.CustomerIndex = 0 then show "ListName" as "ListName" + " - 1"
If GlobalPriceLists.CustomerIndex > 0 (ie has a value from lngContIdx) then show "ListName" as "ListName" + " - 2". There's this example but am not sure as I can't see what the syntax would be for .net: https://editor.datatables.net/manual/php/joins#Options-class. Thanks.
Two options:
Allan
Thanks