Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
50
Copy row to a new row
posted

Hi,

I want to copy a row into a new row when the user click a button placed on each row in a "copy button column" of a WebHierarchicalDataGrid. The grid has a depth of 2 bands, and I want to be able to copy any of the child band into a new row at the bottom of the band. How can I do that?

I've looked many workaround and now I'm using clipboard to copy/paste the row, but I am unable because I cannot select the last row of the band (how may I do that?) and I have to set the unique ID of the added line (I don't know how, I know I have to remember the unique ID).

Thanks!

Parents
  • 50
    posted

    I precise I add a row at the bottom of the band. Some more détails about actual code:

    Grid in .aspx:

    <ig:WebHierarchicalDataGrid ID="whdg" runat="server" AutoGenerateBands="False" AutoGenerateColumns="False" DataKeyFields="ref_ADC_id" Height="600px" InitialDataBindDepth="-1" Key="Niv1" Width="95%" StyleSetName="Default">

    <ClientEvents Click="whdg_ContainerGrid_Click" />

    <Columns>

    <ig:BoundDataField DataFieldName="ref_ADC_id" Key="ref_ADC_id" Hidden="true" Width="65px" />

    <ig:BoundDataField CssClass="Cell_Right_Niv2" DataFieldName="code" Key="code" Width="25px">

    <Header CssClass="Entete_Right" Text="Ordre" />

    </ig:BoundDataField>

    ... (other BoundDataFields)

    <ig:BoundDataField CssClass="Cell_Right_Niv2" DataFieldName="quantite" Key="quantite" Width="50px">

    <Header CssClass="Entete_Right" Text="Quantité" />

    </ig:BoundDataField>

    </Columns>

    <Behaviors>

    <ig:Selection CellClickAction="Row" Enabled="true" RowSelectType="Single" />

    <ig:Activation>

    </ig:Activation>

    <ig:EditingCore>

    <EditingClientEvents RowAdding="Grid_RowAdding" />

    <Behaviors>

    <ig:CellEditing/>

    <ig:RowEditing/>

    <ig:RowDeleting>

    </ig:RowDeleting>

    </Behaviors>

    </ig:EditingCore>

    <ig:Clipboard/>

    <ig:RowSelectors>

    </ig:RowSelectors>

    </Behaviors>

    <Bands>

    <ig:Band AutoGenerateColumns="false" DataKeyFields="heureID" DataMember="Niv2" Key="Niv2" ShowHeader="true">

    <Columns>

    <ig:BoundDataField DataFieldName="heureID" Key="heureID" Hidden="true" Width="65px" />

    <ig:BoundDataField DataFieldName="ref_ADC_id" Key="ref_ADC_id" Hidden="true" Width="65px" />

    ... (other BoundDataFields)
    <ig:TemplateDataField CssClass="Cell_Center" Key="Copy" Width="20px">

    <Header CssClass="Entete_Center" Text="" />

    <ItemTemplate>

    <asp:Image ID="imgCopy" ToolTip="Copier" runat="server" ImageUrl="img/Copier.png" CssClass="imgClickYes" />

    </ItemTemplate>

    </ig:TemplateDataField>

    <ig:TemplateDataField CssClass="Cell_Center" Key="Delete" Width="20px">

    <Header CssClass="Entete_Center" Text="" />

    <ItemTemplate>

    <asp:Image ID="imgDelete" ToolTip="Supprimer" runat="server" ImageUrl="img/Supprimer.png" CssClass="imgClickYes" OnClientClick="DeleteRow(); return false;" />

    </ItemTemplate>

    </ig:TemplateDataField>

    <ig:BoundCheckBoxField CssClass="Cell_Center" DataFieldName="isLivrable" Key="isLivrable" Width="50px" />

    ... (other BoundDataFields)

    </Columns>

    <Behaviors>

    <ig:EditingCore Enabled="true" EnableInheritance="true" AutoCRUD="false" BatchUpdating="True">

    <Behaviors>

    <ig:CellEditing Enabled="true" EditModeActions-EnableF2="true" EnableInheritance="true" EditCellCssClass="Cell_LeftBlueEnabled">

    <ColumnSettings>

    <ig:EditingColumnSetting ColumnKey="code" ReadOnly="false" />

    <ig:EditingColumnSetting ColumnKey="nom" ReadOnly="false" />

    </ColumnSettings>

    <EditModeActions EnableOnKeyPress="True" MouseClick="Double" />

    </ig:CellEditing>

    <ig:RowAdding AddNewRowCssClass="Cell_LeftBlueEnabled" EditCellCssClass="Cell_LeftBlueEnabled" EnableInheritance="True">

    <AddNewRowClientEvents EnteringEditMode="Grid_RowAdding_EnteringEditMode" />

    <EditModeActions EnableOnKeyPress="True" />

    </ig:RowAdding>

    <ig:RowDeleting ButtonHtml="Delete" ShowDeleteButton="false">

    </ig:RowDeleting>

    </Behaviors>

    </ig:EditingCore>

    <ig:RowSelectors RowNumbering="True" Enabled="true">

    </ig:RowSelectors>

    </Behaviors>

    </ig:Band>

    </Bands>

    </ig:WebHierarchicalDataGrid>



    The function that handles to Copy button click event - note that delete button seems to work:


    function whdg_ContainerGrid_Click(sender, eventArgs) {

    if (eventArgs.get_type() == "cell") {

    var columnKey = eventArgs.get_item().get_column().get_key()

    switch (columnKey) {

    case "Delete":

     var grid = sender;

    var gridRows = sender.get_rows();

    var row = eventArgs.get_item().get_row();

    var selectedRows = grid.get_behaviors().get_selection().get_selectedRows();

    for (var i = selectedRows.get_length() - 1; i >= 0; i--) {

    var row = selectedRows.getItem(i);

    gridRows.remove(row);

    }

    break;

    case "Copy":

    var grid = sender;

    var gridRows = sender.get_rows();

    var rowsLength = grid.get_rows().get_length();

    var row = new Array(myRowUniqueID); 

    var selectedRows = grid.get_behaviors().get_selection().get_selectedRows()

    var clip = sender.get_behaviors().getBehaviorByName('Clipboard');

    clip.copy();

    sender.get_rows().add(row);

     

    clip.paste(); //manque juste á coller dans la bonne row

    break;

    }

    }



Reply Children