joeharrison714 / MVCGrid.Net

http://mvcgrid.net
MIT License
74 stars 55 forks source link

Get the Selected Row #8

Open jaydenis opened 9 years ago

jaydenis commented 9 years ago

Is there a way to select a row and get the row values?

Here's what I need to build: -a page with 2 panels (left & right) -a grid of items in the left panel -details in the right panel -when an item (row) is selected information is displayed in the right panel

jaydenis commented 9 years ago

I kind of sorted out what I was trying to achieve: 1 a column w/ a button

cols.Add("Select").WithHtmlEncoding(false)
 .WithSorting(false)
.WithHeaderText(" ")
.WithAllowChangeVisibility(false)
.WithValueTemplate("<a href='#' class='btn btn-primary btn-xs' onclick='selectRow({Model.Id});' >Select</a>");

2 javascript function

function selectRow(id) {

        $.post("/Search/GetItemDetails?id=" + id, function (data) {
            if (data.Status <= 0) {
                alert(data.Message);
                return;
            }
            $("#item-content").html(data.Content);
        });
    }

3 a function in the controller to handle the ajax post

[HttpPost]
public JsonResult GetItemDetails(string id)
 {
  var person= db.Person
        .Single(f => f.Id== id);
 if (person== null){
                return Json(new { Status = 0, Message = "Not found" });
}

return Json(new { Status = 1, Message = "Ok", Content = RenderPartialViewToString("_ItemDetails", person) });
}

This works BUT

joeharrison714 commented 9 years ago

What you could do it create your own razor view for the grid (You can download this one to start): https://raw.githubusercontent.com/joeharrison714/MVCGrid.Net/master/MVCGridExample/Views/MVCGrid/_Grid.cshtml

Follow these instructions for the initial setup: http://mvcgrid.net/demo/customrazorview

Then you could add the checkbox logic with row highlighting into your view.