vtfuture / BForms

Bootstrap Forms for ASP.NET MVC
MIT License
62 stars 33 forks source link

Can't reorder grid. #220

Closed Pepo-BG closed 9 years ago

Pepo-BG commented 9 years ago

I have a BsGrid(...) with sortable columns. When I click the title to reorder, its make Ajax request, I processed the data in Controller and return the correct ordered data. But grid wasn't "refreshed" with ordered data. My code is: public ActionResult List(BsGridBaseRepositorySettings settings) { var all = this._service.GetAll(); var gridItems = AutoMapper.Mapper.Map<List>(all);

        if (settings.OrderableColumns[0].Type == BsOrderType.Descending)
        {
            gridItems = gridItems.OrderByDescending(x => settings.OrderableColumns[0].Name == "Name" ? x.Name : x.Type).ToList();
        }
        else
        {
            gridItems = gridItems.OrderBy(x => settings.OrderableColumns[0].Name == "Name" ? x.Name : x.Type).ToList();
        }
        return Json(new { result = gridItems });
    }

Grid's code in View is: @using (Html.BsGridWrapper()) { @( Html.BsGridFor(m => m.Grid) .ConfigureColumns(cols => { cols.For(x => x.Name).Name("Name"); cols.For(x => x.Date).Name("Date") .Text(i => i.Date.DateValue.GetValueOrDefault().ToString(E_Voting.Core.Common.Formating.DateFormat)); cols.For(x => x.Type).Name("Type"); }) .PagerSettings(new BsPagerSettings { Size = 5, ShowFirstLastButtons = true, ShowPrevNextButtons = true, HasPagesText = true, HasPageSizeSelector = true }) .IgnoreAjaxRequest(true) ) }

the returned data is (when order type is ASC): {"result":[{"ID":1,"Name":"N1 2014","Date":{"TextValue":"13.11.2014 г. 0:00:00","DateValue":"\/Date(1415829600000)\/"},"Type":"E Type"},{"ID":2,"Name":"N2 2014","Date":{"TextValue":"3.12.2014 г. 0:00:00","DateValue":"\/Date(1417557600000)\/"},"Type":"P Type"},{"ID":3,"Name":"N3 2014","Date":{"TextValue":"3.12.2014 г. 0:00:00","DateValue":"\/Date(1417557600000)\/"},"Type":"P Type"}]}

when order is DESC: {"result":[{"ID":2,"Name":"N2 2014","Date":{"TextValue":"3.12.2014 г. 0:00:00","DateValue":"\/Date(1417557600000)\/"},"Type":"P Type"},{"ID":3,"Name":"N3 2014","Date":{"TextValue":"3.12.2014 г. 0:00:00","DateValue":"\/Date(1417557600000)\/"},"Type":"P Type"},{"ID":1,"Name":"N1 2014","Date":{"TextValue":"13.11.2014 г. 0:00:00","DateValue":"\/Date(1415829600000)\/"},"Type":"E Type"}]}

Pepo-BG commented 9 years ago

Update: I updated value which is returned by the controller to be: return Json(new { Status = 1 , Data = viewModel }); where viewModel is from model type in the view. Now, after finished the response - grid disappear.

Pepo-BG commented 9 years ago

I fix the problem when change the method's result to be: return new BsJsonResult(new { Count = gridItems.Count, Html = html }, BsResponseStatus.Success, "");

Where html is rendered string with grid's partial view.

Now you can close the ticket.

stefanprodan commented 9 years ago

You should use BsJsonResult as the returning type of any Ajax calls involving BF components.