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

Set GridDateTimeColumn Default Insert Value to Today with Batch Edit Mode

12 Answers 713 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Amy
Top achievements
Rank 1
Amy asked on 28 Oct 2015, 04:41 PM

Hello,

How do you set default insert value to today for a GridDateTimeColumn in a RadGrid configured to use Batch edit mode?

 

Thank you.

Amy

12 Answers, 1 is accepted

Sort by
0
Maria Ilieva
Telerik team
answered on 29 Oct 2015, 12:11 PM
Hi Amy,

You can set it in the markup like this:

<telerik:GridDateTimeColumn DefaultInsertValue="Today"></telerik:GridDateTimeColumn>




Regards,
Maria Ilieva
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Amy
Top achievements
Rank 1
answered on 29 Oct 2015, 01:10 PM

Thank you for the response Maria.  Unfortunately, this does not work on my end.  When I click the button in the grid to add a new record, the GridDateTimeColumn simply displays the text "Today" in the cell.

I thought that I might have to set this value in one of the client side events such as 'OnBatchEditOpening'.  However, I'm not sure how to distinguish between insert and edit mode in this event, and also I'm not sure how to get a reference to the RadDateTimePicker in the GridDateTimeColumn to set Today's date.

Amy

0
Maria Ilieva
Telerik team
answered on 30 Oct 2015, 01:07 PM
Hello Amy,

Try the following code snippet in order to set current date to DatePicker when in Insert mode.
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
{
    if (e.Item is GridDataInsertItem && e.Item.OwnerTableView.IsItemInserted) 
    {
        GridDataInsertItem insertItem = (GridDataInsertItem)e.Item;
        (insertItem["DateTimeColumn_UniqueName"].Controls[0] as RadDatePicker).SelectedDate = DateTime.Today;
    }
}


Regards,
Maria Ilieva
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Amy
Top achievements
Rank 1
answered on 03 Nov 2015, 06:56 PM

Hello Maria,

From what I understand, a server-side event like ItemDataBound ​is not triggered because Batch Edit is a client-side oriented mode and the entire editing is handled on the client-side.  Thus I don't believe your suggestion above will work. 

Can you please provide some guidance on how to set the default insert value to today for a GridDateTimeColumn in one of the client-side events?

Much appreciated.

Amy

0
Maria Ilieva
Telerik team
answered on 06 Nov 2015, 01:07 PM
Hello,

With batch editing you can use the following:

protected void RadGrid1_PreRender(object sender, EventArgs e)
{
    GridTableView masterTable = ((RadGrid)sender).MasterTableView;
    GridDateTimeColumnEditor editor = masterTable.GetBatchColumnEditor("OrderDate") as GridDateTimeColumnEditor;
    RadDatePicker picker = editor.PickerControl;
    picker.SelectedDate = DateTime.Today;
}


Regards,
Maria Ilieva
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Amy
Top achievements
Rank 1
answered on 06 Nov 2015, 02:13 PM

Thank you for the suggestion, but this is not working on my end.  Is it possible for you to provide a runnable example where this is working?  Or, suggest a way to do this in one of the client-side events?

Thank you,

Amy

0
Maria Ilieva
Telerik team
answered on 12 Nov 2015, 09:06 AM
Hi Amy,

It appears that we have an issue with setting default insert value when batch editing is enabled and this issue is logged in our system for further investigation.

Meanwhile you can handle the client OnRowCreated event and apply the default date like this:
function RowCreated(sender, args) {
                           if (args.get_itemIndexHierarchical() < 0) {
                               args.get_tableView().get_dataItems();
                               var cell = args.get_tableView().getCellByColumnUniqueName(args.get_gridDataItem(), "HireDate");
                               args.get_tableView().get_owner().get_batchEditingManager().changeCellValue(cell, new Date().toString());
                           }
                       }

I hope this helps.

Regards,
Maria Ilieva
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Edward
Top achievements
Rank 1
answered on 12 Nov 2015, 09:22 AM

<telerik:RadGrid ID="RadGrid1" runat="server" AllowAutomaticInserts="true" DataSourceID="SqlDataSource1">
    <MasterTableView EditMode="Batch" DataKeyNames="EmployeeID" CommandItemDisplay="Top">
        <Columns>
            <telerik:GridDateTimeColumn UniqueName="BirthDateColumn" DataField="BirthDate"></telerik:GridDateTimeColumn>
            <telerik:GridTemplateColumn Display="false">
                <ItemTemplate>
                    <%(RadGrid1.MasterTableView.GetColumn("BirthDateColumn") as GridEditableColumn).DefaultInsertValue = DateTime.Now.ToString();%>
                </ItemTemplate>
            </telerik:GridTemplateColumn>
        </Columns>
    </MasterTableView>
</telerik:RadGrid>
 

Regards,

Edward

 

0
Amy
Top achievements
Rank 1
answered on 12 Nov 2015, 08:20 PM

Thank you Maria and Edward for your suggestions.  Please see the results of my test below:

  1. Maria's suggestion using the OnRowCreated event.

    - Sets the initial date with the proper formatting.

    - However, the date is not saved when the Save button is clicked.  Note that I am saving the grid data using the method as described here - http://www.telerik.com/forums/how-do-i-save-2-radgrids-by-only-1-outside-button.

  2. Edward's suggestion using an additional hidden column.
    - Sets the initial date, but does not have the proper formatting.

    - The date is not saved when the Save button is clicked.

Almost have a working solution...  But is seems that the BatchEditingManager doesn't think that there are table changes when setting the initial date this way.

0
Maria Ilieva
Telerik team
answered on 17 Nov 2015, 12:02 PM
Hi Amy,

After fixing the bug below you will be able to achieve the required functionality:

http://feedback.telerik.com/Project/108/Feedback/Details/172538-setting-defaultinsertvalue-does-not-work-for-a-batch-editing-grid

We increase its priority and I hope that the fix will be available in the next official release of the controls.

Regards,
Maria Ilieva
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Saxon
Top achievements
Rank 1
answered on 15 Jan 2016, 03:55 AM
Was it fixed on latest release in 2016?
0
Maria Ilieva
Telerik team
answered on 15 Jan 2016, 11:06 AM
Hi,

This issue is already fixed. You can upgrade your applictaion to test the fix locally and let us know if it works fr you.

Regards,
Maria Ilieva
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
Grid
Asked by
Amy
Top achievements
Rank 1
Answers by
Maria Ilieva
Telerik team
Amy
Top achievements
Rank 1
Edward
Top achievements
Rank 1
Saxon
Top achievements
Rank 1
Share this question
or