This is a migrated thread and some comments may be shown as answers.

Excel like edit

6 Answers 314 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Saurabh Srivastava
Top achievements
Rank 1
Saurabh Srivastava asked on 20 Aug 2009, 11:42 AM
Hi,

I am trying to incorporate excel like edit feature for my grid. I have 7 columns out of which only 1 is editable. The editable column is a RadComboBox. I load the grid in edit mode with the combox values populated in it.

I am trying to find a way to identify the updated rows on click of my "Upload" button.

Could you please suggest an approach?

Regards,
Saurabh

6 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 20 Aug 2009, 11:59 AM
Hi Saurabh,

Here is a code library submission which explains how to implement an Excel like Grid .
ExcelLikeGrid

You may loop through all the rows which are in edit mode in the Upload button's click event and perform the Batch update.
Performing batch updates

Thanks
Shinu
0
Saurabh Srivastava
Top achievements
Rank 1
answered on 20 Aug 2009, 01:13 PM
Hi Shinu,

Thanks for the response. I have been through these links and they have indeed helped me in implementing the excel edit feature. But my problem is that I am unable to understand how to identify the updated records. Here is my scenario:

1. Only the dropdowncolumn is editable.
2. The dropdown is loaded with a list of values, the first being a "default" (Please select) item.
3. There is an upload button on my form which would upload the updated/changed records. This is not in the grid but outside the grid.

Given the above scenario, what would be the best approach for me?

I was thinking of applying a client side indexchanged event to the dropdown to assign the record id to a server variable and use that server variable. But again the question is that how to I get the row id of the grid on the indexchanged event of the dropdown?
0
Saurabh Srivastava
Top achievements
Rank 1
answered on 20 Aug 2009, 02:58 PM
Hi Shinu,

Update:

I was able to figure out a strategy for my requirement. I have created a CommandItem "Update" and used it to perform batch updates as depicted in the Knowledge base article.

A slight issue here is that my dropdown selection is not valid if I go to the next page, or if I do any operations like sort, filter etc.

My dropdown is defined as
<telerik:GridDropDownColumn UniqueName = "CargoType" DataField="grades"  HeaderText = "Cargo Type" AllowFiltering ="false" AllowSorting="false"  ListTextField="CargoTypeName" ListValueField="CargoTypeId"></telerik:GridDropDownColumn> 

The code behind for this is
    protected void rgMissingJourneys_ItemDataBound(object sender, GridItemEventArgs e)  
    {   
if (e.Item is GridEditableItem && e.Item.IsInEditMode)  
        {  
            GridEditableItem eeditedItem = e.Item as GridEditableItem;  
            if (editedItem != null)  
            {  
                GridEditManager editMan = editedItem.EditManager;  
 
                GridDropDownListColumnEditor editor = (GridDropDownListColumnEditor)(editMan.GetColumnEditor("CargoType"));  
                editor.DataSource = cargoTypeList;  
                editor.DataBind();  
                editor.ComboBoxControl.Items.Insert(0, new RadComboBoxItem("Please select", "0"));  
}  
}  
}  
 



0
Saurabh Srivastava
Top achievements
Rank 1
answered on 25 Aug 2009, 09:40 AM
Hi,

Could someone please respond? The sample in the KB article is not complete in most respects.

1. It does not show any other controls apart from the textbox even though it mentions that the scenario would still be the same. However, it would not be the same as the dropdown would lose its selection if you perform operations like sort, filter, paging etc.

2. No mention of filters, sorting, paging and how to handle the dataset/datatable.

3. No mention of improving/optimizing performance as when the grid loads in edit mode, it takes some time.

My scenario is like follows:

I have an analysis batch module which runs a set of business rules on the source records each week. Of this, some records fail analysis due to missing data. I have to provide the user with a grid, with these "failed" records, along with the ability to update the missing data (which is just one field). The users would go and update multiple records and then upload these.

My implementation is:

1. Have the grid load in edit mode.
2. Missing data column is a dropdown column (The only editable column)
3. Populate the grid and the dropdown on page load
4. Put the datatable in viewstate.
5. Configure needdatasource, itemdatabound, itemcommand event
6. On Itemdatabound, assign the missing data list to the dropdown.
7. Configured Sorting, Filtering and Paging.
8. On ItemCommand (for sort/filter/page), I access my datatable and update the row values if the missing data has changed.

Issues:
1. On ItemCommand (for update), when I do e.Item.OwnerTableView.ExtractValuesFromItem(newValues, editedItem), this would give me only 10 rows (current page of the grid). How do I get updated rows from previous pages? I know I can loop through the entire datatable and find the updated record, but that is too performance intensive

2. After update, how do I refresh the datatable and the grid.

Please respond as this is urgent. I have asked this question in multiple posts but have not got a response yet. If required, I can open up a support ticket, but sending a project would require more time from my end.

Regards,
Saurabh



0
Yavor
Telerik team
answered on 26 Aug 2009, 11:39 AM
Hello Saurabh,

Onto your questions:

  1. Indeed, in operations like sorting/filtering, the selection of the dropdown will be lost. This is because the grid is rebound. In such scenarios, it is up to you to preserve any changes made to the nested controls, and restore them on postback.
  2. When the control is in edit mode, the filtering/sorting operations will be handled as expected. If you persist the new values in the underlying database, the filtering/sorting will reflect the new changes as well.
  3. The whole approach for this setup is not a trivial one, and relies heavily on client script to handle the navigation among the cells. This is what leads to some slowdown. This can be worked around by changind the logic of the navigation. Instead of assigning onKeyPres for each control, the logic can be moved to the  onKeyPress client side handler for the grid. This will represent so overhead with respect to the logic, but the main approach remains similar.

I hope this information helps.

All the best,
Yavor
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Saurabh Srivastava
Top achievements
Rank 1
answered on 26 Aug 2009, 12:19 PM
Thanks for the response, Yavor.

I was indeed able to work out the logic to piece all the required functionality together.

Regards,
Saurabh
Tags
Grid
Asked by
Saurabh Srivastava
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Saurabh Srivastava
Top achievements
Rank 1
Yavor
Telerik team
Share this question
or