Telerik Forums
UI for ASP.NET MVC Forum
4 answers
559 views
Hello,

I need to reload the grid based on a dropdown change but I don't want to do the filtering.  I don't want the grid to preload all of the data and then filter.  I want it only to load based on the dropdown.  But when I set it up the way I think it should work it is calling my controller method twice.  The first time passing the parameter correctly from the dropdown and the second time passing a null.

Here is the view:
<div class="filter">
    <label class="filter-label" for="filter">Filter:</label>
    @(Html.Kendo().DropDownList()
        .Name("filter")
        .DataTextField("Text")
        .DataValueField("Value")
        .Events(e => e.Change("onChange"))
        .BindTo(new List<SelectListItem>() {
            new SelectListItem() {
                Text = "Pending Reviews",
                Value = "N"
            },
            new SelectListItem() {
                Text = "Complete Reviews",
                Value = "Y"
            }
        })
    )
</div>
 
<br class="clear" />
<br />
 
      
@(Html.Kendo().Grid<PASSAdmin.ViewModels.ResourceReviewer.ResourceReviewViewModel>()
    .Name("gridResourceReviews")
    .Columns(columns =>
    {
        columns.Command(command => { command.Edit(); }).Width(50);
        columns.Bound(m => m.Proposal_ID).Title("Proposal ID");
        columns.Bound(m => m.Proposal_Title).Title("Title");
        columns.Bound(m => m.PI_BNL_ID).Title("PI");
        columns.Bound(m => m.Date_Submitted).Title("Date Submitted");
    })
    .Editable(editable => editable.Mode(GridEditMode.PopUp).TemplateName("ResourceReviewer/ResourceReview").Window(window => window.Width(700)))
    .Pageable()
    .Sortable()
    .Events(e => e.Edit("onEdit"))   
    .DataSource(dataSource => dataSource
        .Server()
        .Model(model =>
        {
            model.Id(m => m.Beamtime_Request_ID);
            model.Field(m => m.Beamline_Request_ID);
        })
        .Read(read => read.Action("GetResourceReviews", "ResourceReviewer"))
        .Update(update => update.Action("AddResourceReview", "ResourceReviewer"))     
    ))
 
<script type="text/javascript">
function onEdit(e) {
    $(e.container).parent().css({
        width: '700px',
        height: '350px'
    });
    $(e.container.find(".k-edit-buttons.k-state-default")).css("width", "660px");
}
 
function onChange() {
    var filter = this.value();
    alert(filter);
    $.get('/ResourceReviewer/GetResourceReviews', { reviewComplete: filter }, function (data) {
        var grid = $("#gridResourceReviews").data("kendoGrid");
        grid.dataSource.read();
    });
}
</script>


And here is the controller method:
public ActionResult GetResourceReviews(string reviewComplete, [DataSourceRequest]DataSourceRequest request)
{
    User user = new User();
    int user_id = user.GetUserIDByBNLAccount(User.Identity.Name);
    int resource_id = UserSession.LastViewedResourceID.GetValueOrDefault();
 
    if (UserPermissions.VerifyResourceRole(user_id, resource_id, "Resource_Reviewer"))
    {
        using (PASSEntities context = new PASSEntities())
        {
            var vm = (from a in context.Beamtime_Requests
                      join b in context.Proposals on a.Proposal_ID equals b.ID
                      join c in context.Technique_Requests on a.ID equals c.Beamtime_Request_ID
                      join d in context.Beamline_Requests on c.ID equals d.Technique_Request_ID
                      join e in context.Beamlines on d.Beamline_ID equals e.ID
                      join f in context.Users on b.PI_User_ID equals f.ID
                      where a.Status == "BLREV" && d.Beamline_ID == resource_id && d.Beamline_Review_Complete == reviewComplete
                      select new ResourceReviewViewModel()
                      {
                          Date_Submitted = a.Date_Submitted,
                          Beamline_Request_ID = d.ID,
                          Beamtime_Request_ID = a.ID,
                          Proposal_ID = b.ID,
                          Proposal_Type_ID = b.Proposal_Type_ID,
                          Beamline_Review_Complete = d.Beamline_Review_Complete,
                          Current_Cycle_Request = a.Current_Cycle_Request,
                          PI_User_ID = b.PI_User_ID,
                          PI_BNL_ID = b.User.BNL_ID,
                          Proposal_Title = b.Title,
                          Refused_By_Beamline = d.Refused_By_Beamline
                      }).ToList();
 
            DataSourceResult result = vm.ToDataSourceResult(request);
            return Json(result, JsonRequestBehavior.AllowGet);
        }
    }
    else
    {
        return RedirectToAction("Index");
    }
}











Stephen
Top achievements
Rank 1
 answered on 22 Apr 2014
4 answers
937 views
Hi,

i am using batch editing grid,is there any solution for checking weather my data is edited or not  in grid using javascript 
Dimo
Telerik team
 answered on 22 Apr 2014
2 answers
53 views
Is it possible to change the default location that the JS files for Kendo UI are placed, when upgrading a project?
Donald
Top achievements
Rank 1
 answered on 21 Apr 2014
16 answers
2.8K+ views
Hello,

I am looking for a way to change the contenttype in the http request,  it seems you can do it in jquery but there doesn't seem to be a way to do it with the razor html helpers.  I would think it would work something like line #6.  Is this possible?

Thanks,



01..DataSource(dataSource => dataSource
02.        .Ajax()
03.        .PageSize(20)
04.        .ServerOperation(true)
05.        .Events(events => events.Error("error_handler"))y
06.        .Create(update => update.Action("Customer_Create", "Customer", ContentType="Application/Json")
07.                
08.        )
09.        .Read(read => read.Action("Customer_Read", "Customer"))
10.        .Update(update => update.Action("Customer_Update", "Customer"))
11.        .Destroy(update => update.Action("Customer_Delete", "Customer"))
12.        .
13.        
14.    )
15.)

   
Robert
Top achievements
Rank 1
 answered on 21 Apr 2014
1 answer
257 views
I have looked all over.  I would think this would be simple to do.  If I have a listview control inside of a MVC form.  How do I get the items selected in the listview to post back to the controller?
Alexander Popov
Telerik team
 answered on 21 Apr 2014
3 answers
297 views
Hello.
I have a scheduler and an EditorTemplate.
I want to bind a multiselectfor after the reading method. (with my Model which is populated in the read Method).
I suppose the .BindTo() Display nothing because the read method 'll be call after this one.

So here is my scheduler :

@(Html.Kendo().Scheduler<iMail.Web.Models.TaskViewModel>()
            .Name("scheduler")
            .Date(DateTime.Now)
            .Timezone("Etc/UTC")
            .Views(views =>
            {
                views.DayView();
                views.WeekView();
                views.MonthView();
                views.AgendaView(agenda => agenda.Selected(true));
            })
            .Selectable(true)
            .Timezone("Etc/UTC")
            .Events(e =>
            {
                e.Edit("onEdit");
                e.Change("onChange");
            })
            .Editable(editable =>
            {
                editable.TemplateName("_EditorTemplatePartial");
            })
            .DataSource(d => d
                    .Model(m =>
                    {
                        m.Id(f => f.TaskID);
                        m.Field(f => f.Title).DefaultValue("No title");
                        m.RecurrenceId(f => f.RecurrenceID);
                        m.Field(f => f.Priority);
                        m.Field(f => f.TypeID);
                    })
                .Events(e => e.Error("error_handler"))
                .Read (read => read.Action("TasksRead", "Calendar").Data("additionalInfo").Type(HttpVerbs.Get))
                .Create(create => create.Action("TasksCreate", "Calendar").Data("additionalInfo"))
                .Destroy(destroy => destroy.Action("TasksDestroy", "Calendar").Data("additionalInfo"))
                .Update(update => update.Action("TasksUpdate", "Calendar").Data("additionalInfo"))
            )
        )



And here is my MultiSelectFor in the _EditorTemplatePartial.cs file.
<div id="AttendeeAlreadyInvited">
    <div data-container-for="AlreadyInvitedID" class="k-edit-field">
        @(Html.Kendo().MultiSelectFor(model => model.AlreadyInvitedID)
            .HtmlAttributes(new { data_bind = "value:AlreadyInvitedID" })
            .DataTextField("Name")
            .DataValueField("ID")
            .BindTo(Model.Invited) 
        )
    </div>
</div>

Model.Invited has a structure like this :

public class CalEmployeeLight
{
  public int ID;
  public string Name;
 }

Here is a part of my model :

public class TaskViewModel : Kendo.Mvc.UI.ISchedulerEvent
{
   public int TaskID { get; set; } //each event have an ID.
   .....
   public IEnumerable<
int> AlreadyInvitedID { get; set; }
   public ICollection<CalEmployeeLight> Invited { get; set; }
}

Each event in the Scheduler have an ID (TaskID)

The Model is populated in the TaskRead fct and works correctly.
But my multiselectFor is empty.

How can i use .bindTo() fct in the MultiSelectFor() after the Model is populated by "TaskRead" ?

Alexander Popov
Telerik team
 answered on 21 Apr 2014
2 answers
152 views
Hi,

          I trying to do on treeview item select populate the kendogrid something like this EXAMPLE ..  which used dropdownlist instead of treeview , I'm trying to do the same for treeview any help appreciated.


Thank you
Bharathi
Top achievements
Rank 2
 answered on 18 Apr 2014
1 answer
288 views
Hi,

I'm currently developing an application with the support of Windsor Castle (DI container).

As I also want to use Kendo in this project, I started with a simple Grid.

Suddenly the Exception "no parameterless constructor defined for this object" came up.

I've found some threads about this on the net - like this one (http://www.telerik.com/forums/binding-to-an-arraylist-4539b158237a) - which are talking about the same error.
But the solution suggested in those are not satisfying, because I don't want to introduce a parameterless constructor if I don't need one (beside of Kendo).

Is there a way to use Kendo without having parameterless constructors?

Thanks in advance.

Kind regards
Daniel
Petur Subev
Telerik team
 answered on 18 Apr 2014
2 answers
120 views
Is Kendo 2014.1.415 not yet in cdn?
I am getting errors when attempting to use the latest version.
Vladimir Iliev
Telerik team
 answered on 18 Apr 2014
4 answers
702 views
Hi,

I have a stored procedure which returns  2 result sets. First result-set is collection of Columns ,data types, column order, Is column sortable and is column filterable. 
Second resultset is actual data for the columns which are there in first resultset. So in short my stored procedure returns the metadata for the columns and their values. I dont know in advance what will be my columns list. At code level stored procedure is  returning a dataset with 2 tables inside it.  Now I want to bind the kendo grid with the second table of dataset and first table of dataset will give me information about the columns which are suppose to have sort ,filter criteria. My problem is  i dont know the columns in advance still i execute the stored procedure then how can i use DataSourecRequest object to find out custom sorting and filtering stuff.
e.g. 
private CriteriaDto GetCriteriaDtoValues(DataSourceRequest request)
        {
           var criteriaDto = new DocumentHistoryCriteriaDto { Filters = new Dictionary<string, string>() };
            if (request.PageSize == 0)
            {
                request.PageSize = 20;
                criteriaDto.PageSize = 20;
            }
            else
            {
                criteriaDto.PageSize = request.PageSize;
            }
            if (request.Sorts != null && request.Sorts.Count > 0)
            {
                foreach (SortDescriptor sortDescriptor in request.Sorts)
                {
                    if (sortDescriptor.SortDirection == ListSortDirection.Ascending)
                    {
                        switch (sortDescriptor.Member)
                        {
                            case "ActivityDate": //This is hard coded column just for example but by this time i dont knwo what are the columns there in resultset
                                criteriaDto.SortBy = "ActivityDate";
                                criteriaDto.IsSortAcending = true;
                                currentSortType = criteriaDto.SortBy;
                                break;
                            case "RecordId": ////This is hard coded column just for example but by this time i dont knwo what are the columns there in resultset
                                criteriaDto.SortBy = "RecordId";
                                criteriaDto.IsSortAcending = true;
                                currentSortType = criteriaDto.SortBy;
                                break;                            
                        }
                    }
                    else
                    {
                        switch (sortDescriptor.Member)
                        {
                            case "ActivityDate": //This is hard coded column just for example but by this time i dont knwo what are the columns there in resultset
                                criteriaDto.SortBy = "ActivityDate";
                                criteriaDto.IsSortAcending = false;
                                currentSortType = criteriaDto.SortBy;
                                break;
                            case "RecordId": //This is hard coded column just for example but by this time i dont knwo what are the columns there in resultset
                                criteriaDto.SortBy = "RecordId";
                                criteriaDto.IsSortAcending = false;
                                currentSortType = criteriaDto.SortBy;
                                break;                            
                        }

                    }
                }
            }
            else
            {
                criteriaDto.SortBy = "ActivityDate"; //This is hard coded column just for example but by this time i dont know what are the columns there in resultset
                criteriaDto.IsSortAcending = true;
                currentSortType = criteriaDto.SortBy;
            }
            if (request.Filters != null && request.Filters.Count > 0)
            {
                foreach (FilterDescriptor filterDescriptor in request.Filters)
                {
                    switch (filterDescriptor.Member)
                    {
                        case "RecordId": //This is hard coded column just for example but by this time i dont know what are the columns there in resultset
                            criteriaDto.Filters.Add("LoanNo", filterDescriptor.Value.ToString());
                            break;
                    }

                }
            }
            if (request.Page > 0)
            {
                criteriaDto.PageNumber = request.Page;
            }
            return criteriaDto;

        }  

Also I have written below ajax method which is calling the above code before it calls the Store procedure. Can you provide some exmaple on how I can actually
pass the data set's data table collection to view in MVC  and How can i bind it to grid for 2nd table in dataset and how can i make use of first table
to decide which columns to sort and filter using DataSourceRequest object

 public ActionResult View_ByRecordId_Read([DataSourceRequest] DataSourceRequest request)
{
        
DataSet dsModel;
int  total=0;
int RecordId = 2;
string RecordValue = "0000224374";
 int timeFrame = 50;

 criteriaDto = this.GetCriteriaDtoValues(request);  //So here it calls this method to decide which columns got sort and filer criteria but actually by this time i dint get my procedure called so how can i figure it out which columns are meant to be for sorting and filtering.

dsModel = this._Service.GetDocumentView (userDto.Id,RecordId,RecordValue,timeFrame,criteriaDto,Guid.NewGuid());  //This is calling stored procedure and returning a dataset with 2 tables inside it.

if (dsModel != null && dsModel.Tables.Count > 0)        {
 bool tryParse=int.TryParse(dsModel.Tables[1].Rows[0]["TotalCount"].ToString(),out  total);    }

            var  result = new DataSourceResult() { Data = dsModel.Tables, Total = total };

            return Json(result);

        }
Aarti
Top achievements
Rank 1
 answered on 17 Apr 2014
Narrow your results
Selected tags
Tags
+? more
Top users last month
Jay
Top achievements
Rank 3
Bronze
Iron
Iron
yw
Top achievements
Rank 2
Iron
Iron
Stefan
Top achievements
Rank 2
Iron
Iron
Iron
Kao Hung
Top achievements
Rank 1
Iron
Bohdan
Top achievements
Rank 2
Iron
Iron
Iron
Want to show your ninja superpower to fellow developers?
Top users last month
Jay
Top achievements
Rank 3
Bronze
Iron
Iron
yw
Top achievements
Rank 2
Iron
Iron
Stefan
Top achievements
Rank 2
Iron
Iron
Iron
Kao Hung
Top achievements
Rank 1
Iron
Bohdan
Top achievements
Rank 2
Iron
Iron
Iron
Want to show your ninja superpower to fellow developers?
Want to show your ninja superpower to fellow developers?