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

[Solved] Custon Add new button in Telerik MVC grid

1 Answer 70 Views
Grid
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
As
Top achievements
Rank 1
As asked on 29 Sep 2011, 07:31 PM
Hi,
I have custom 'Add New' button in grid. On click of that button, it should pop up a new window and the value that is selcted is then inserted into the grid..  I have that working, but after inserting a new row, the built in 'Save Changes' button is not working..
Here is my code

@(Html.Telerik().Grid<

AccountingProgram>(Model.AccountingPrograms)  

.Name("AccountingProgramsGrid")  

.DataKeys(keys => keys.Add(item => item.AcProgramId))

.EnableCustomBinding(true)  

.Editable(editing => editing.Mode(GridEditMode.InCell))  

.Columns(columns =>

{

columns.Bound(pgm => pgm.GroupId).Title("Accounting Program Id");  

columns.Bound(pgm => pgm.EvaluationTemplateName).Title("Evaluation Template Name").ReadOnly();  

columns.Bound(pgm => pgm.TypeOfEntityDesc).Title("Type Of Entity").ReadOnly();  

columns.Command(commands => commands.Delete()).Title(

"Delete");  

}) 
.Scrollable(scrl => scrl.Height("auto"))  

.Filterable(filtering => filtering.Enabled(false))  

.Groupable(grouping => grouping.Enabled(false))  

.DataBinding(dataBinding => dataBinding.Ajax().Update("_SaveBatchEditing", "SPEPrograms"))  

.ToolBar(commands =>{

commands.Custom().Text( 

"Add New").HtmlAttributes(new {@onclick="ClickEvent();return false;"});  

//commands.Insert();  

commands.SubmitChanges(); 

}))

Here is the javascript code

 

function ClickEvent() {  

$.ajax({url: "/Search/AcctPgmSearch",  

type: "Get",  

success: function (data) {  

 var features = "height=700,width=800,scrollTo,resizable=1,scrollbars=1,location=0";

 newwindow = window.open( 

'/Search/AcctPgmSearch', 'Popup', features);  

}

});

} 

function AddToGrid(col) { 
 var newItem1 =col; //get new val 1 

var lastGridRow = $("#AccountingProgramsGrid tbody tr:last"); //Get the current last row in the grid  

var gridItems = $("#AccountingProgramsGrid tbody"); //Get the grid row container 

 

var lastIsAlternateRow = lastGridRow.hasClass("t-alt"); //see if the current last row has the alternating

 

var rowClass = "";
if (!lastIsAlternateRow) //if the last row is not the alternate style, then the new one needs to have it

 

rowClass = "t-alt"; 

 

gridItems.append( 

"<tr class='" + rowClass + "'><td>" + newItem1 + "</td></tr>"); //append the new row to the grid row

}

1 Answer, 1 is accepted

Sort by
0
As
Top achievements
Rank 1
answered on 29 Sep 2011, 11:29 PM
Somebody please reply!!
Tags
Grid
Asked by
As
Top achievements
Rank 1
Answers by
As
Top achievements
Rank 1
Share this question
or