Thread View: alt.pl.comp.lang.csharp
2 messages
2 total messages
Started by Macko
Mon, 19 Sep 2011 08:35
jqGrid i MVC 3
Author: Macko
Date: Mon, 19 Sep 2011 08:35
Date: Mon, 19 Sep 2011 08:35
71 lines
3648 bytes
3648 bytes
Cze,
więc mam sobie jqGrida posadzonego na stronce:
<script type="text/javascript">
$(function () {
jQuery("#places").jqGrid({
url: '@Url.Action("GetPlaces", "Trip", new { id =
@Model.Trip.Id })',
datatype: 'json',
colNames: ['Id', 'Nazwa', ''],
colModel: [
{ name: 'id', index: 'id', width: 40, align: 'left' },
{ name: 'etykieta', index: 'etykieta', width: 440, align:
'left' },
{ name: 'myname', sortable: 'false', edittype: 'select',
formatter: 'showlink', formatoptions: { baseLinkUrl: 'someurl.php',
addParam: '&action=edit'} },
],
rowNum: 10,
rowList: [10, 20, 30],
pager: '#pager2',
sortname: 'Etykieta',
viewrecords: true,
sortorder: "desc",
loadtext: "Pobieranie danych ...",
caption: "JSON Example"
});
jQuery("#places").jqGrid('navGrid', '#places_pager', { edit:
false, add: false, del: false });
});
</script>
A więc w urlu do jqGrida jest przekazywany id np. /Trip/GetPlaces/30
i działa sobie fajnie (wyświetla wszystkie atrakcje, czyli wszystkie
rekordy z tabeli).
Ja bym chciał żeby działał fajniej tzn wyswietlal atrakcje tylko dla
podanej podrozy.
Warstawa danych poprzez NH obsługuje to jednak nie wiem jak teraz
odczytać w kontrolerze Id podrozy.
Oto metoda w kontrolerze wysyłająca dane do jqGrida:
public ActionResult GetPlaces(string sidx, string sord, int
page, int rows)
{
var searcher = new PlacesSearcher()
{
PageNumber = page,
RowsPerPage = rows,
SortOrder = JQueryHelper.OrderToEnum[sord]
};
var places = Repository.Places.GetAll(searcher);
var result = new
{
total = places.TotalPages,
page = places.PageNumber,
records = places.Count,
rows = (from x in places select new { id = x.Id, cell
= new string[] { x.Id.ToString(), x.Etykieta, "bla" } }).ToArray()
};
return Json(result, JsonRequestBehavior.AllowGet);
}
--
Pozdro,
Maćko
Re: jqGrid i MVC 3
Author: Macko
Date: Tue, 18 Oct 2011 08:18
Date: Tue, 18 Oct 2011 08:18
74 lines
4023 bytes
4023 bytes
On 19 Wrz, 10:35, Macko <rychter.mac...@gmail.com> wrote:
> Cze,
>
> więc mam sobie jqGrida posadzonego na stronce:
>
> <script type="text/javascript">
> $(function () {
> jQuery("#places").jqGrid({
> url: '...@Url.Action("GetPlaces", "Trip", new { id =
> @Model.Trip.Id })',
> datatype: 'json',
> colNames: ['Id', 'Nazwa', ''],
> colModel: [
> { name: 'id', index: 'id', width: 40, align: 'left' },
> { name: 'etykieta', index: 'etykieta', width: 440, align:
> 'left' },
> { name: 'myname', sortable: 'false', edittype: 'select',
> formatter: 'showlink', formatoptions: { baseLinkUrl: 'someurl.php',
> addParam: '&action=edit'} },
> ],
> rowNum: 10,
> rowList: [10, 20, 30],
> pager: '#pager2',
> sortname: 'Etykieta',
> viewrecords: true,
> sortorder: "desc",
> loadtext: "Pobieranie danych ...",
> caption: "JSON Example"
> });
> jQuery("#places").jqGrid('navGrid', '#places_pager', { edit:
> false, add: false, del: false });
> });
> </script>
>
> A więc w urlu do jqGrida jest przekazywany id np. /Trip/GetPlaces/30
>
> i działa sobie fajnie (wyświetla wszystkie atrakcje, czyli wszystkie
> rekordy z tabeli).
> Ja bym chciał żeby działał fajniej tzn wyswietlal atrakcje tylko dla
> podanej podrozy.
> Warstawa danych poprzez NH obsługuje to jednak nie wiem jak teraz
> odczytać w kontrolerze Id podrozy.
>
> Oto metoda w kontrolerze wysyłająca dane do jqGrida:
>
> public ActionResult GetPlaces(string sidx, string sord, int
> page, int rows)
> {
> var searcher = new PlacesSearcher()
> {
> PageNumber = page,
> RowsPerPage = rows,
> SortOrder = JQueryHelper.OrderToEnum[sord]
> };
>
> var places = Repository.Places.GetAll(searcher);
>
> var result = new
> {
> total = places.TotalPages,
> page = places.PageNumber,
> records = places.Count,
> rows = (from x in places select new { id = x.Id, cell
> = new string[] { x.Id.ToString(), x.Etykieta, "bla" } }).ToArray()
> };
>
> return Json(result, JsonRequestBehavior.AllowGet);
> }
>
> --
> Pozdro,
> Maćko
Nie ważne, już nie trzeba.
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads