Chris
Chris

Reputation: 215

Issue with kendo, no data in the grid

I've been looking for this since days now ! So i hope someone could help.

It's a big project so i can't put it all here but if you need more code just tell me and i will add it.

So i have a grid that should contains what's inside my database. But instead i got a k-no-data, can't figure out why.

There is my grid :

<section id="main-content">
<section class="wrapper site-min-height">
    <div class="row">
        <div class="col-lg-10 main-chart">
            <div class="border-head">
                <h3>Results</h3>
            </div>
            <div class="col-lg-12 col-md-3 col-sm-12">
                <div class="showback">
                    <h4>Text example</h4>
                    <div class="panel panel-info">
                        <div class="panel-body">
                            @(Html.Kendo().Grid<DisplayGridResultatsPrestations>
                                ()
                                .Name("GridListeIdcc")
                                .Columns(columns =>
                                {
                                    columns.Bound(c => c.CategoriePrestation);
                                    columns.Bound(c => c.DesignationPrestation);
                                    columns.Bound(c => c.ValeurPreconisee);
                                    columns.Bound(c => c.ValeurProposee);
                                    columns.Bound(c => c.DesignationResultat);
                                })
                                .Filterable()
                                .Selectable(selectable => selectable.Mode(GridSelectionMode.Single).Type(GridSelectionType.Row))
                                .DataSource(datasource => datasource
                                .Ajax()
                                .Read(reader => reader.Action("THISISCONFIDENTIAL", "Comparaison", new { identifiantResultatsComparaison }))
                                .Model(model =>
                                {
                                    model.Id("Id");
                                })
                                .Group(group => group.Add(c => c.SOMETHINGCONFIDENTIALTOO))
                                .ServerOperation(true)))
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</section>

function onSelection(arg) 
{
    var grid = $("#GridListeIdcc").data("kendoGrid");
    var selectedItem = grid.dataItem(grid.select());
}

So i think it should work, but nothing happen i just have a header on my grid with title but no value.

I know it's not really clear but if i miss something important i think you will tell.

public JsonResult THISICONFIDENTIAL([DataSourceRequest] DataSourceRequest request,
        string identifiantResultatsComparaison)
    {
        var resultats = _resultatComparaisonService.FindResultatById(identifiantResultatsComparaison);

        var listePrestations = resultats.ListeDesPrestationsApresComparaison;
        List<DisplayGridResultatsPrestations> diplayListeResultats = listePrestations.Select(prestation => new DisplayGridResultatsPrestations
        {
            CCN = prestation.NomAccordSante + " (" + prestation.IdentifiantAccordSante + ")",
            IdentifiantAccord = prestation.IdentifiantAccordSante,
            CategoriePrestation = prestation.CategoriePrestation,
            NomPrestation = prestation.NomPrestation,
            Resultat = prestation.ResultatComparaison,
            ValeurPreconisee = prestation.ValeurPreconisee,
            ValeurProposee = prestation.ValeurProposee,
            DesignationPrestation = prestation.DesignationPrestation,
            DesignationResultat = (prestation.ResultatComparaison) ? "OK ✔" : "KO ✘"
        }).ToList();

        return Json(diplayListeResultats.ToDataSourceResult(request, c => new
        {
            c.CategoriePrestation,
            c.CCN,
            c.IdentifiantAccord,
            c.DesignationPrestation,
            c.Resultat,
            c.DesignationResultat,
            c.ValeurPreconisee,
            c.ValeurProposee
        }), JsonRequestBehavior.AllowGet);

Upvotes: 0

Views: 197

Answers (1)

David Shorthose
David Shorthose

Reputation: 4497

Ok. Thanks for posting the signature for the read controller. This helps a lot.

All you need to do is make a simple change to the read method on your grid from:

.Read(reader => reader.Action("THISISCONFIDENTIAL", "Comparaison", new { identifiantResultatsComparaison }))

to

.Read(reader => reader.Action("THISISCONFIDENTIAL", "Comparaison").Data("identifiantResultatsComparaison"))

By declaring the read function like this it tells the read action to grab the additional data from your identifiantResultatsComparaison javascript function.

Then have a function that returns your string back like so:

function identifiantResultatsComparaison(){
   var mystringValue = '';
  //do something here 

 return { identifiantResultatsComparaison: mystringValue }
}

Hopefully this is clear what you need to do but if not I will expand the answer with updates for you.

Upvotes: 1

Related Questions