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

Grid Question. Is it possible to save a row in a grid on click of a cell?

5 Answers 40 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Rod
Top achievements
Rank 1
Rod asked on 29 Jun 2012, 03:51 PM

My Scenario
I have a grid which allows inline editing. When the user clicks a hyperlink in any row I open a radwindow. The hyperlink is a template cell  and I open the RadWindow via javascript which all works fine except that I need to be able to save the row before opening the radwindow if it is in edit mode because I'm passing in the unique id of the row and if it is a new row I need to perform the insert command first so that the Id is generated on the server. The data is in SQL and the Id is an Identity column. I'm also using automatic updates on the grid. 

My Question
Is it possible to save the row and invoke the insert command when the user clicks the hyperlink/template cell? If so can you provide sample code on how this could be done from javascript or server side code. Both would be idea. Thank you!

Here is the template column used to open the RadWindow
<telerik:GridTemplateColumn HeaderText="Selection Options" UniqueName="SelectionOptions" AllowFiltering="false">

    <ItemTemplate><a href="#"

     onclick='openAnswerOptionsWindow(&#039;<%# DataBinder.Eval(Container.DataItem, "LCFormMetadataId") %>&#039;); return false;'>

     SelectionOptions</a></ItemTemplate>

</telerik:GridTemplateColumn>


Here is the javascript I use to open the RadWindow

function openLCFormManagementWindow() {
    var oWnd = radopen("LCFormMaintenance.aspx");
    oWnd.Center();

}

5 Answers, 1 is accepted

Sort by
0
Maria Ilieva
Telerik team
answered on 04 Jul 2012, 12:29 PM
Hi Rod,

You could simply fire and insert command on the client like this:

function openLCFormManagementWindow() {
    var masterTable = $find("<%= RadGrid1.ClientID %>").get_masterTableView();  
    masterTable.fireCommand("InitInsert","");  
    var oWnd = radopen("LCFormMaintenance.aspx");
    oWnd.Center();
  
}

Let me know if this works in your case.

Kind regards,
Maria Ilieva
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
Rod
Top achievements
Rank 1
answered on 17 Jul 2012, 04:34 AM
Hi Maria,

Thankyou for the information but unfortunately this doesn't solve my problem. When I execution the code you provided it inserts a new row into the grid (I.e. it performs the "Add New" function.) What I need however is to know if the current row is in edit mode for an existing record or in edit mode for a new record and then perform the "Update" command for and existing record that is in edit more or the "Insert" command  for a new record. Is there a way to do that?

Thanks again for you assistance.
0
Maria Ilieva
Telerik team
answered on 19 Jul 2012, 01:45 PM
Hi Rod,

In case you need to save the edited item before opening the insert window you could try the following:
function openLCFormManagementWindow()
  
    {
  
        var grid = $find('<%= RadGrid1.ClientID %>');
        var masterTable = $find("<%= RadGrid1.ClientID %>").get_masterTableView();
  
        var idx = grid._editIndexes[0];
  
        if (idx != null)
  
        {
  
            masterTable.updateItem(parseInt(idx));
  
        }
  
        else
  
        {
  
            masterTable.fireCommand("InitInsert","");
            var oWnd = radopen("LCFormMaintenance.aspx");
            oWnd.Center(); 
  
        }
  
    };


All the best,
Maria Ilieva
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
Rod
Top achievements
Rank 1
answered on 20 Jul 2012, 03:17 AM
Hi Maria,

This gets me closer to what I'm trying to achieve however if the row is not in edit mode then the idx variable will always be null. For example clicking the hyperlink on an existing row that has already been saved and is not in edit mode will have a null idx value. I think I have a way around that though. If I can access the Id of the record then I'll know if it is a new record that hasn't been inserted or if it is an existing record that has already been inserted. I'd also like to retrieve other values form the row so that I can pass the data to the RadWindow. Is there a way for me to do that?

Here's the onclick event that I use to call the javascript function to open the window.
onclick='openWindow(&#039;<%# DataBinder.Eval(Container.DataItem, "LCFormMetadataId") %>&#039;); return false;'>

Is it possible to pass in multiple values to the openWindow function when it is called?

Is it possible to retireve values from the row from within the "openWindow" function?

Thanks for you help!
0
Maria Ilieva
Telerik team
answered on 25 Jul 2012, 01:41 PM
Hello Rod,

In order to access the edited item I would suggest you to review the following help topic which provides an approach for getting it on the client:
Accessing cells and rows

As for the window parameters please review the online demo below that presents similar functionality:
http://demos.telerik.com/aspnet-ajax/controls/examples/integration/gridandwindow/defaultcs.aspx?product=window

Regards,
Maria Ilieva
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Tags
Grid
Asked by
Rod
Top achievements
Rank 1
Answers by
Maria Ilieva
Telerik team
Rod
Top achievements
Rank 1
Share this question
or