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

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

6 Answers 127 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Artur
Top achievements
Rank 1
Artur asked on 24 May 2016, 06:58 PM

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

6 Answers, 1 is accepted

Sort by
0
Artur
Top achievements
Rank 1
answered on 25 May 2016, 05:03 PM
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?
0
Maria Ilieva
Telerik team
answered on 27 May 2016, 09:37 AM
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.
0
Artur
Top achievements
Rank 1
answered on 27 May 2016, 09:49 AM

Thank you for your replay.

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

0
Maria Ilieva
Telerik team
answered on 31 May 2016, 12:51 PM
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.
0
Artur
Top achievements
Rank 1
answered on 02 Jun 2016, 10:44 AM

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>

0
Maria Ilieva
Telerik team
answered on 07 Jun 2016, 03:02 PM
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.
Tags
Grid
Asked by
Artur
Top achievements
Rank 1
Answers by
Artur
Top achievements
Rank 1
Maria Ilieva
Telerik team
Share this question
or