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
225
Update the grid data and columns on button click
posted

Hi Team,

I want to update the grid's data and structure on button click.

Scenario is as below:

I have created a hierarchical grid using MVC GridModel class (defined columns and features in controller) and in View, I  have written: @Html.Infragistics().Grid(Model). This works fine.

Now the requirement is like this:

I have a multi select check box list, where there are a list of columns. I need to pass the selected columns (may be as a comma separated list) and re-create the grid with the selected columns.

Issue 1:

I am able to create and bind the igCombo with multiple selection. But when I try to fetch the selected values, I receive errors:

If I use: var selectedItems = $("#possibleColumnsCheckBox").igCombo("selectedItems") and loop through the selectedItems, and try to fetch the value using:
selectedItems[i].value, I get undefined (though it loops the number of items selected).

When I try to use: var selectedItems = $("#possibleColumnsCheckBox").igCombo("values"), I get the error:
no such method 'values' for igCombo widget instance  

How to select the value of this checkbox list.

Issue 2:


On button click, I manually pass the value using a post request, call a action method, create the grid, pass the column list (should be the one selected above, but for now, I manually create it), fetch data for these columns from database, define features and return the ViewResult and try to render the updated grid.

I keep the AutoGenerateColumns to true here and binds the grid with the updated datasource. But, when I debug, I find that the grid has no columns and the updated grid is not rendered on the view.

Not sure, what is the issue here. Could you please help me resolve these two issues.

-Regards,

Agraj

Parents
  • 17590
    Offline posted

    Hello Agraj,

    Thank you for your patience while I was looking into this matter for you.

    What I can suggest regarding your first query is getting reference to the data of the selected item and afterwards get the value of particular property. For example, if you are binding the igCombo and set the textKey option to a field called ID and the valueKey option to a field called Name when you would like to get the ID of a particular selected item it should look as following:

    //if you would like to get the ID value

    var selectedItemID =  $("#combo").igCombo("selectedItems")[i].data.ID;

    //if you would like to get the Name value

     $("#combo").igCombo("selectedItems")[i].data.Name;

    By design igHierarachicalGrid could not change its column collection dynamically. What can I suggest in case that you would like to change the columns structure  is to destroy the grid and create it again with the new data source. This could be done with the destroy method of igGrid. For example:

    $(".selector").igGrid("destroy");

    I hope you will find my information helpful.

    Please let me know if you need any further assistance with this matter.

Reply Children