DefaultInsertValue doesn't work when using args.set_cancel(true);

7 posts, 0 answers
  1. Artur
    Artur avatar
    6 posts
    Member since:
    Apr 2016

    Posted 24 May Link to this post

    Hi there,

    I have a grid attached to an EntityDataSource. The grid is in "Batch" mode and has enabled "AllowAutomaticInserts". I also have a javascript attached to "OnBatchEditOpening" that prevents two columns from being edited. When inserting a new record I need to set these two columns with default values, but again the columns have to be in read only mode. I've tried to use "DefaultInsertValue" but then the javascript causes an error "Unable to get property 'cell' of undefined or null reference" when adding a new row.

    Javascript

    function BatchEditOpening(sender, args)
    {
        var columnUniqueName = args.get_columnUniqueName();
        switch (columnUniqueName)
        {
            case "Status":
            case "Source":
                args.set_cancel(true);
            default:
        }
    }

    How can I solve this? Is there another approach I can take?

    Regards,

    Artur

  2. Artur
    Artur avatar
    6 posts
    Member since:
    Apr 2016

    Posted 25 May in reply to Artur Link to this post

    I got rid of the javascript and make both columns "ReadOnly=true" and "DefaultInsertValue=[default value]". When saving to a database NULLs are being sent. How can I set a dafult value for a column on insert?
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Maria Ilieva
    Admin
    Maria Ilieva avatar
    4017 posts

    Posted 27 May Link to this post

    Hi,

    We had such an issue in previous versions of the control that is already fixed. You can see the item below:
    http://feedback.telerik.com/Project/108/Feedback/Details/172538-setting-defaultinsertvalue-does-not-work-for-a-batch-editing-grid

    Please make sue that you are using Q1 2016 version of the control or newer version and see how it goes.


    Regards,
    Maria Ilieva
    Telerik
    Do you need help with upgrading your ASP.NET AJAX, WPF or WinForms projects? Check the Telerik API Analyzer and share your thoughts.
  5. Artur
    Artur avatar
    6 posts
    Member since:
    Apr 2016

    Posted 27 May in reply to Maria Ilieva Link to this post

    Thank you for your replay.

    The version Telerik.Web.UI is 2016.2.504.45. Is that OK?

  6. Maria Ilieva
    Admin
    Maria Ilieva avatar
    4017 posts

    Posted 31 May Link to this post

    Hello,

    This version should work properly in this scenario. Can you please share the whole grid markup as well as the related client script and code behind so that we can revise them locally and advise you further?

    Regards,
    Maria Ilieva
    Telerik
    Do you need help with upgrading your ASP.NET AJAX, WPF or WinForms projects? Check the Telerik API Analyzer and share your thoughts.
  7. Artur
    Artur avatar
    6 posts
    Member since:
    Apr 2016

    Posted 02 Jun in reply to Maria Ilieva Link to this post

    Hello,

    Here's the code (there are no script or code behind).

    <telerik:RadGrid RenderMode="Lightweight" ID="RadGrid1" runat="server" Skin="Silk"
        AllowPaging="true" PageSize="20" AllowSorting="true"
        AllowAutomaticDeletes="true" AllowAutomaticInserts="true" AllowAutomaticUpdates="true" AutoGenerateColumns="False" CellSpacing="-1" GridLines="Both" DataSourceID="EntityDataSource1" AllowMultiRowEdit="True">
        <MasterTableView CommandItemDisplay="Top" ClientDataKeyNames="RecordId" DataKeyNames="RecordId" EditMode="Batch" DataSourceID="EntityDataSource1">
            <Columns>
                <telerik:GridBoundColumn DataField="RecordId" HeaderText="RecordId" DataType="System.Int32" Visible="false" SortExpression="RecordId"></telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="PayrollNo" HeaderText="PayrollNo" SortExpression="PayrollNo"></telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="TAOff" HeaderText="TAOff" DataType="System.Int32" SortExpression="TAOff"></telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="GradeCode" HeaderText="GradeCode" SortExpression="GradeCode"></telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="StaffNo" HeaderText="StaffNo" SortExpression="StaffNo"></telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="Date" HeaderText="Date" DataType="System.DateTime" SortExpression="Date"></telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="PayCode" HeaderText="PayCode" SortExpression="PayCode"></telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="PayCodeDescription" HeaderText="PayCodeDescription" SortExpression="PayCodeDescription"></telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="DebitCredit" HeaderText="DebitCredit" SortExpression="DebitCredit"></telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="CostAmount" HeaderText="CostAmount" DataType="System.Double" SortExpression="CostAmount"></telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="CodeBlock" HeaderText="CodeBlock" SortExpression="CodeBlock"></telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="TechGfisAccount" HeaderText="TechGfisAccount" DataType="System.Int32" SortExpression="TechGfisAccount"></telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="Source" HeaderText="Source" ReadOnly="true" DefaultInsertValue="UserInput" FilterControlAltText="Filter Source column" SortExpression="Source" UniqueName="Source"></telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="Status" HeaderText="Status" ReadOnly="true" DefaultInsertValue="0" FilterControlAltText="Filter Status column" SortExpression="Status" UniqueName="Status"></telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="amount" HeaderText="amount" DataType="System.Decimal" FilterControlAltText="Filter amount column" SortExpression="amount" UniqueName="amount"></telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="NewPayCode" HeaderText="NewPayCode" FilterControlAltText="Filter NewPayCode column" SortExpression="NewPayCode" UniqueName="NewPayCode"></telerik:GridBoundColumn>
            </Columns>
        </MasterTableView>
        <ClientSettings AllowKeyboardNavigation="true">
            <Virtualization EnableVirtualization="true" InitiallyCachedItemsCount="1000" ItemsPerView="100" />
            <Scrolling AllowScroll="true" UseStaticHeaders="true" ScrollHeight="500px" />
        </ClientSettings>
    </telerik:RadGrid>
    <asp:EntityDataSource runat="server" ID="EntityDataSource1" DefaultContainerName="uk_converter_newEntities" ConnectionString="name=uk_converter_newEntities" EnableFlattening="False" EntitySetName="Northgates"
        EntityTypeFilter="Northgate" OrderBy="it.[RecordId] desc" EnableDelete="true" EnableInsert="true" EnableUpdate="true"></asp:EntityDataSource>

  8. Maria Ilieva
    Admin
    Maria Ilieva avatar
    4017 posts

    Posted 07 Jun Link to this post

    Hi Artur,

    The provided code looks absolutely correct. i have tested the same case in the online demo below by adding DefaultInsertValue for the columns and it behalves as expected.

    http://localhost:34225/Telerik.Web.Examples/Grid/Examples/Data-Editing/batch-editing/DefaultCS.aspx

    In this case it will be best if you can open a regular support ticket and send us isolated runnable version of your application that demonstrates the issue. Thus we will be able to debug it locally and advise you further.

    Regards,
    Maria Ilieva
    Telerik
    Do you need help with upgrading your ASP.NET AJAX, WPF or WinForms projects? Check the Telerik API Analyzer and share your thoughts.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017