Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
495
igGrid Databinding question
posted

Hello,

Our model contains a property which contains the gridmodel. In the model we also get the data (not in the controller) and we set the datasource of the grid and it's layout :

public class DocumentErrorsViewModel

{

       public override GridModel GridFiltering { get; set; }

public DocumentErrorsViewModel()
{
   GridFiltering = new Infragistics.Web.Mvc.GridModel();
   GridFiltering.DataSource = GetGridData();

   GridFiltering.Width = "100%";
   GridFiltering.Columns.Add(new GridColumn("Scanner", "ScannerName", "string", "70%"));
   GridFiltering.Columns.Add(new GridColumn("Scan date time", "ScanTime", "date", "30%"));

   ...


}

private IQueryable<DocumentErrorGridModel> GetGridData()
{

...

return ...

}

}

In our controller we just give back our model, nothing more, nothing less :-)

public class ScanController : Controller
{

public ActionResult Index()

{
   var model = new ScanErrorsViewModel();
   return View(model);
}

}

In our webpage we just add our grid:

@Html.Infragistics().Grid("grid1", Model.GridFiltering)

Everything just works fine, but when we want to refresh the data of our grid (Refresh-button on the webpage) we don't want to refresh our entire webpage but only the datasource of the grid.

I tried to use the DataSourceUrl in the controller to trigger an action:

public ActionResult Index()
{
   var model = new ScanErrorsViewModel();
   model.GridFiltering.DataSourceUrl = Url.Action("BindGridFiltering");
   return View(model);
}

[GridDataSourceAction]
[ActionName("BindGridFiltering")]
public ActionResult BindGridFiltering()
{
    // Get datasource in model
    var ds = ...
    return View("RowSelection", ds);
}

But this does not work. I would think that the action will also be triggered when the page will be loaded (so the datasource would be fetched twice), but the action doesn't go off.

Other problem is that I don't know how to access the model from the controller...

Do I have to use another technique or am I missing something ?

  • 12773
    posted

    Hi,

    Have you been able to take a look at the provided sample application? If you have any other questions or concerns about this matter please do not hesitate to contact us.

  • 1800
    Suggested Answer
    posted

    Hi,

     

    In your case you can set DataSourceUrl and not setting DataSource property. You should define Action controller. Btw I can send you a sample I think it should fit your needs - and also it is for hierarchical grid with enabled filtering but can be easily modified for flat grid(you can remove/comment definition for columnlayouts) and also it defines the grid in similar way you have used.

    Thanks,

    Miro

    remote igHierarchical.zip