This is a migrated thread and some comments may be shown as answers.

Table with One Column That is the Primary ID

3 Answers 64 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Adam
Top achievements
Rank 1
Adam asked on 25 Jan 2013, 11:13 PM
I am using a grid to edit a table that is one column and that column is the primary ID. Therefore, I cannot edit the column. I want to allow adds and deletes (with checks in the background). There are two problems. I do not see the Add or Delete button in line. If I use the pop-up option, I can only add but the pop-up button states that I am editing, which would be confusing to the users. How do I get the grid to add and delete properly?

This is what I have:
@(Html.Kendo().Grid<NatureOfStudyViewModel>()
    .Name("NatureOfStudyGrid")
    .Columns(columns =>
        {
           columns.Bound(item => item.NatureOfStudy);            
        })
        .DataSource(ds => ds
            .Ajax()
            .Model(model =>
            {
                model.Id(m => m.NatureOfStudy);
            })
            .Read(read => read.Action("NatureOfStudyDataSource", "Lists"))
            .Create(create => create.Action("NatureOfStudyCreate","Lists"))
            .Destroy(destroy => destroy.Action("NatureOfStudyDelete","Lists"))
            .Events(events => events.Error("listValueDataSource_error"))
        )
    .Pageable()
    .ToolBar(commands => commands.Create())
    .Editable(edit => edit.Mode(GridEditMode.PopUp))
    )


 

 

 

 

 

 

 

 

 

 

 

 


3 Answers, 1 is accepted

Sort by
0
Rene
Top achievements
Rank 1
answered on 27 Jan 2013, 02:43 PM
Add this to your column definitions:

columns.Command(command =>
            {
               command.Edit();         
             command.Destroy();     
            });

just before your:

columns.Bound(item => item.NatureOfStudy); 

Also

.Model(model => {
model.Id(m => m.NatureOfStudy).DefaultValue( "" );  // default value is based on the data type of m.NatureOfStudy
        })

0
Adam
Top achievements
Rank 1
answered on 28 Jan 2013, 04:54 PM
Your solution gives me the Delete button (I cannot have the Edit button you had in your response - it is a table with one column that is the primary key), but the add only works with the pop-up, which is fine. I now see the delete button. The issue remaining is the pop-up.
 
The pop-up has "Edit" in the top bar ad "Update" in the button. This is not correct - you are adding.. How do I change the text bar to say "Add" and the button to say "Add"? Also, how to I change the name of the box they type into from "NatureOfStudy" to "Nature of Study"?


Thanks.
0
Dimiter Madjarov
Telerik team
answered on 30 Jan 2013, 09:25 AM
Hi Nancy,

You could bind to the edit event of the grid (which fires when an element is added or edited), handle the "add" case and modify the title of the window.
e.g.

.Events(e => e.Edit("onEdit"))

function onEdit(e) {
    if (e.model.id == 0) {
        var editWindow = e.container.data("kendoWindow");
        editWindow.title("Add");
        $("label[for='NatureOfStudy']").html("Nature Of Study");
    }
}


Kind regards,
Dimiter Madjarov
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Tags
Grid
Asked by
Adam
Top achievements
Rank 1
Answers by
Rene
Top achievements
Rank 1
Adam
Top achievements
Rank 1
Dimiter Madjarov
Telerik team
Share this question
or