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

update batch grid with a file upload

3 Answers 69 Views
Grid
This is a migrated thread and some comments may be shown as answers.
seputro
Top achievements
Rank 1
seputro asked on 15 Dec 2014, 09:02 PM
Hello,

I have been trying to get the batch grid to work with a file upload. The aim is to update the grid with the information in the text file. Would this be a common scenario which has been tried before? 

For temporary solution, I processed the uploaded file and save it in the server and render the partial view which contain
@html.Kendo().Grid()

Then, during loading of the partial view, the Read( read.Action ("Test","TestController")) is invoked and load the data from the text file.

Is there a way to set the dirty flag manually after the initial load of the grid so that I can click the save button?

Thank you,

-sk 

3 Answers, 1 is accepted

Sort by
0
Dimiter Madjarov
Telerik team
answered on 17 Dec 2014, 01:26 PM
Hello Seputro,


Indeed saving the file and reading it's content in the read action of the Grid's dataSource seems the correct approach in the current case. Regarding the last question, could you please provide further details why is setting the dirty flag required?

Regards,
Dimiter Madjarov
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
seputro
Top achievements
Rank 1
answered on 18 Dec 2014, 03:30 AM
Hi Dimiter, 

Thank you for your quick respond. 

Initially I was thinking that the "submit" button in the grid can only be activated when manual changes are detected in the grid. But in my case I didn't make any changes in the grid - data in the grid was loaded from Read action. So I couldn't send the data.  I thought without setting the dirty flag after the initial Read Action I would not be able to submit the data in the grid.

Then, I found the following link in the forum http://www.telerik.com/support/code-library/save-all-changes-with-one-request which allow me to iterate the grid and submit the data. 

Here is my use case:
1. user upload a file
2. grid should show the data in the file ( I was using temporary file approach to load it from Read when the grid is loaded)
3. user change data in the grid
4. user click submit to send data to database

This approach seem to work but I am not convinced that this the best solution. Plus i was having problem with dateTime Column when iterating the row in the grid. 

The list used contains objects which have DateTime property.

  private static List<Test> _TestList = new List<Test>()
        {
            new Test() {   Id = 0, TestDate = DateTime.Now.AddDays(1) }
            new Test() {   Id = 1, TestDate = DateTime.Now.AddDays(2) }
        }

Test object has 
[DisplayFormat(DataFormatString = "{0:dd MMM yyyy}")]
 public DateTime TestDate { get; set; }



This list is used in the Read action to initialize the grid. When text file is uploaded, the TestDate will be replaced by the following code:

_TestList [index].TestDate = new DateTime(int.Parse(dateItems[2]), int.Parse(dateItems[1]), int.Parse(dateItems[0]));

After clicking the submit button, the correspond action is invoked and passing the data to controller. In the controller the value of TestDate changes to {01/01/0001 12:00:00 AM}. I wonder if this is a bug in the grid, or just my implementation of the dateTime.

Thank you again for your help.

Regards,
sk











0
Dimiter Madjarov
Telerik team
answered on 18 Dec 2014, 04:12 PM

Hello Seputro,


As you stated, requests will be submitted when the "Save changes" button is pressed, only when there are changes made in the Grid. It is not clear for us what is expected to be submitted in the current case (since the data is already available on the back end when the text file was read) and no changes were made in the Grid.

Regarding the linked code library, this approach is required only when all types of Grid changes should be submitted in a single request. The default behavior of the Grid is to submit a separate requests for the created, updated and deleted items.

As for the date issue, have you tried adding the DataType annotation attribute?
E.g.

[DataType(DataType.Date)]
public DateTime TestDate { get; set; }

If the problem is persisting, please send us an isolated runnable example that demonstrates it, so we could inspect it locally.

Regards,

Dimiter Madjarov

Telerik

 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
Grid
Asked by
seputro
Top achievements
Rank 1
Answers by
Dimiter Madjarov
Telerik team
seputro
Top achievements
Rank 1
Share this question
or