Set GridDateTimeColumn Default Insert Value to Today with Batch Edit Mode

13 posts, 0 answers
  1. Amy
    Amy avatar
    27 posts
    Member since:
    Sep 2010

    Posted 28 Oct 2015 Link to this post

    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

  2. Maria Ilieva
    Admin
    Maria Ilieva avatar
    4017 posts

    Posted 29 Oct 2015 Link to this post

    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
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Amy
    Amy avatar
    27 posts
    Member since:
    Sep 2010

    Posted 29 Oct 2015 in reply to Maria Ilieva Link to this post

    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

  5. Maria Ilieva
    Admin
    Maria Ilieva avatar
    4017 posts

    Posted 30 Oct 2015 Link to this post

    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
  6. Amy
    Amy avatar
    27 posts
    Member since:
    Sep 2010

    Posted 03 Nov 2015 in reply to Maria Ilieva Link to this post

    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

  7. Maria Ilieva
    Admin
    Maria Ilieva avatar
    4017 posts

    Posted 06 Nov 2015 Link to this post

    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
  8. Amy
    Amy avatar
    27 posts
    Member since:
    Sep 2010

    Posted 06 Nov 2015 in reply to Maria Ilieva Link to this post

    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

  9. Maria Ilieva
    Admin
    Maria Ilieva avatar
    4017 posts

    Posted 12 Nov 2015 Link to this post

    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
  10. Edward
    Edward avatar
    13 posts
    Member since:
    Sep 2011

    Posted 12 Nov 2015 Link to this post

    <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

     

  11. Amy
    Amy avatar
    27 posts
    Member since:
    Sep 2010

    Posted 12 Nov 2015 Link to this post

    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.

  12. Maria Ilieva
    Admin
    Maria Ilieva avatar
    4017 posts

    Posted 17 Nov 2015 Link to this post

    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
  13. Saxon
    Saxon avatar
    7 posts
    Member since:
    Nov 2015

    Posted 14 Jan in reply to Maria Ilieva Link to this post

    Was it fixed on latest release in 2016?
  14. Maria Ilieva
    Admin
    Maria Ilieva avatar
    4017 posts

    Posted 15 Jan Link to this post

    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
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017