2014-02-11 72 views
0

我有一個主視圖,其中包含3個局部視圖。其中一個局部視圖包含應該可排序的kendo網格。kendo ui網格排序局部視圖

@(Html.Kendo().Grid(Model) 
    .Name("tasksgrid") 
    .Sortable() 
    .Filterable() 
    .HtmlAttributes(new { style = "height:100%; font-size:14px;" }) 
    .Columns(columns => 
    { 
     columns.Bound(e => e.Url).Title("URL").Hidden(); 
     columns.Bound(e => e.Id).Title("ID").Hidden(); 

     columns.Template(@<img src="@item.OperatorCreated.ImageSource" style="width:80px;height:80px;"/>).ClientTemplate(" ").Width(100).Title("Picture"); 
     columns.Bound(e => e.Subject).Template(@<div> 
      <div style="font-size: 20px;">@item.OperatorCreated.Name</div> 
      <div>@item.Subject<br />@item.Message</div> 
     </div>).Title("Details").HtmlAttributes(new {id = "detailcolumn"}); 
     columns.Bound(e => e.DateTimeCreated).Title("Date").Width(100).HtmlAttributes(new { id = "datecolumn" }); 
    })   
    .Selectable(selectable => selectable.Mode(GridSelectionMode.Single)) 
     .DataSource(dataSource => dataSource 
      .Server() 
      .Model(model => model.Id(p => p.Id)) 
     ) 
    .Events(events => events.Change("onChange")) 
    .Scrollable() 
) 

僅當選擇了其他視圖中的某個動作時纔會呈現此局部視圖。然後檢索數據以填充網格。

function RefreshTasks(name) { 
    var serviceUrl = "/Tasks/PopulateTasks?actionname=" + name; 
    var request = $.post(serviceUrl); 

    request.done(
     function (data) { 
      $("#tasks").html(data); 
     } 
    ); 
} 

當排序上創建以下網址電網完成 「本地主機:1772/tasksgrid排序= DateTimeCreated降序排序& tasksgrid組= & tasksgrid過濾器=」 它刷新整個頁面這意味着我對電網的局部觀點已經不存在了。

有沒有辦法只把這個網址放到局部視圖中。

我找到了一種方法來完成我需要的這個實現。

$("#tasksgrid .k-link").click(function (e) {//call the function when column header is clicked 
    var thelink = e.target.href;//get the url that would be navigated to on sort 

    var serviceUrl = thelink; 
    var request = $.post(serviceUrl);//post the url 

    request.done(
     function (data) { 
      $("#tasks").html(data);//update div 
     } 
    ); 

    return false;//cancels navigation 
}) 

回答

1

您應該將網格配置爲使用Ajax綁定。否則,它會刷新整個頁面。更多信息請登錄documentation