I have a grid bound to a ViewModel, and the 3rd column is bound to an empty property. This data did not come from a database,so there is no foreign key relationship, in fact there's no database involved at all. In the 3rd column I would like a drop down. This would be the same dropdown in each row of the grid. That dropdown should contain a list of properties (List<string>). When a value is selected,that specific item should be removed from the dropdown list on subsequent rows.
So how can I go about building such a beast? It's easy enough to do in a WebForm, but alas using MVC and these Kendo components has left a real bad taste in my mouth. It seems as if everything has to be gotten via an AJAX call, or must call into some action, or must be bound somewhere along the line; and nothing seems to work out of the box.
I'm using this to map a CSV file to an object. So using the file uploader action, I parse the column headers out of the CSV file, and create a List<CVSColumn> that is actually a property of my CSVColumnsViewModel:
namespace
FileUploader_Mapper.Models
{
public
class
CSVColumn
{
public
int
ColumnNumber {
get
;
set
; }
public
string
ColumnName {
get
;
set
; }
public
string
MappedTo {
get
;
set
; }
}
public
class
CSVColumnsViewModel
{
public
string
CSVFile {
get
;
set
; }
public
List<CSVColumn> Columns =
new
List<CSVColumn>();
public
List<
string
> Properties {
get
;
set
; }
public
CSVColumnsViewModel()
{
Properties =
new
List<
string
>
{
"FirstName"
,
"LastName"
,
"SSN"
,
"Address1"
,
"Address2"
,
"City"
,
"State"
,
"Zip"
};
}
}
}
In the first column of the grid is the ColumnNumber property, the second column is the ColumnName property, and the 3rd column is empty, but is mapped to the MappedTo property. What I want to do is show the list of Properties in a dropdown in the third column so the user can choose which property the current column would map to. Then in the next row, it would only show available properties for the additional columns to map to.
I hope this is making sense...
Here's what I have in my cshtml file
@using FileUploader_Mapper.Models
@model CSVColumnsViewModel
@{
ViewBag.Title = "Result";
}
<
style
>
.k-grid td {
line-height: 2em;
padding: 0 0 0 1em;
}
</
style
>
<
h2
>Result</
h2
>
<
p
></
p
>
@(Html.Label("lblMisc", "Columns from CSV File: " + Model.CSVFile))<
br
/>
@(Html.Kendo().Grid(Model.Columns)
.Name("csvGrid")
.HtmlAttributes(new { style = "width: 650px" })
.Columns(col =>
{
col.Bound(c => c.ColumnNumber).Width(125).Title("Column Number");
col.Bound(c => c.ColumnName).Title("Column Name");
col.Bound(c => c.MappedTo).Title("Mapped To");
})
.DataSource(ds => ds
.Ajax()
.PageSize(20)
.ServerOperation(false)
.Model(m =>
{
m.Id(c => c.ColumnNumber);
m.Field(c => c.ColumnName).Editable(false);
m.Field(c => c.MappedTo).DefaultValue(Model.Properties);
})
)
.Pageable()
)
I really don't know how to proceed and could use some guidance.