Get the value of new cell select via javascript

Answered (Verified) This post has 1 verified answer | 29 Replies | 2 Followers Thread's RSS feed.

jcvegan
Points 420
Replied On: Thu, Feb 9 2012 11:40 AM Reply

I 'm using the webdatagrid v11.1 and need to do a validation. I  have created a datatable and bind it to a webdatagrid wich generate all  the columns needed.

But some cells are left blank, so I want to make a validation using this event: SelectionClientEvents-CellSelectionChanging to find if the new cell has content, if it has no content, cancel the selection, else the selection will continue.

This is the aspx code for webdatgrid

<ig:WebDataGrid ID="wdgCalendario" runat="server" Height="350px" Width="100%">

                            <Behaviors>

                                <ig:Activation Enabled="true" ActivationClientEvents-ActiveCellChanging="OnActiveCellChanging" />

                                <ig:Selection RowSelectType="None" CellClickAction="Cell" Enabled="true" CellSelectType="Single" SelectionClientEvents-CellSelectionChanging="OnCellChanging" SelectionClientEvents-CellSelectionChanged="OnCellChanged"></ig:Selection>

                                <ig:RowSelectors></ig:RowSelectors>

                            </Behaviors>

                        </ig:WebDataGrid>

And I hva no idea how this validation can be done via javascript.

  • Post Points: 20

Verified Answer

Answered (Verified) Replied On: Mon, Feb 13 2012 6:06 AM Reply
Verified by jcvegan

Hi jcvegan,

 

Thank you for posting in our forum.

 

I would suggest that you handle the CellSelectionChanged client side event of the grid. You could use code, similar to the following to check if the selected cell is empty and deselect it, if it is:

 

        function WebDataGrid1_Selection_CellSelectionChanged(sender, eventArgs) {

            //gets the selected cell

            var selectedCell = eventArgs.getSelectedCells().getItem(0);

            //gets the value of the cell

            var cellValue = selectedCell.get_value();

            //if the value is null remove the selected cell from the selected cells collection

            if (cellValue == null) {

                sender.get_behaviors().get_selection().get_selectedCells().remove(selectedCell);

            }

        }

 

Please let me know if this helps.

Best Regards,
Nikolay
Developer Support Engineer
Infragistics, Inc.
http://www.infragistics.com/support

  • Post Points: 40

All Replies

Answered (Verified) Replied On: Mon, Feb 13 2012 6:06 AM Reply
Verified by jcvegan

Hi jcvegan,

 

Thank you for posting in our forum.

 

I would suggest that you handle the CellSelectionChanged client side event of the grid. You could use code, similar to the following to check if the selected cell is empty and deselect it, if it is:

 

        function WebDataGrid1_Selection_CellSelectionChanged(sender, eventArgs) {

            //gets the selected cell

            var selectedCell = eventArgs.getSelectedCells().getItem(0);

            //gets the value of the cell

            var cellValue = selectedCell.get_value();

            //if the value is null remove the selected cell from the selected cells collection

            if (cellValue == null) {

                sender.get_behaviors().get_selection().get_selectedCells().remove(selectedCell);

            }

        }

 

Please let me know if this helps.

Best Regards,
Nikolay
Developer Support Engineer
Infragistics, Inc.
http://www.infragistics.com/support

  • Post Points: 40
jcvegan
Points 420
Replied On: Mon, Feb 13 2012 9:02 AM Reply

Works like a charm! thanks!

  • Post Points: 20
Replied On: Mon, Feb 13 2012 10:34 AM Reply

Hello jcvegan,

I'm glad I could help.

If you have any other questions, please do not hesitate to ask. 

Best Regards,
Nikolay
Developer Support Engineer
Infragistics, Inc.
http://www.infragistics.com/support

  • Post Points: 20
jcvegan
Points 420
Replied On: Mon, Feb 13 2012 10:48 AM Reply

How can I assign the active cell as a selected cell?

  • Post Points: 20
Replied On: Mon, Feb 13 2012 11:08 AM Reply

Hello jcvegan,

You could try to do this using the following code:

var activeCell = sender.get_behaviors().get_activation().get_activeCell();

sender.get_behaviors().get_selection().get_selectedCells().add(activeCell);

 If you have any further questions please feel free to contact me.

Best Regards,
Nikolay
Developer Support Engineer
Infragistics, Inc.
http://www.infragistics.com/support

  • Post Points: 20
jcvegan
Points 420
Replied On: Mon, Feb 13 2012 3:09 PM Reply

Nikolay, I want to paint a cell background and change the foreground if pass some conditionals...

My code on Visual basic is like this

Protected Sub WebDataGrid_OnInitializeRow(ByVal sender As Object, ByVal e As RowEventArgs)

   if(conditional) then

      e.e.Row.Items.Item(index).CssClass = "Custom1"

   end if

End Sub

 

On css:

Custom1{

   background:#E01B1B;

   color:#FFFFFF;

   font-weight:bold;

}

 

The grid result only paint the foreground not the background, how can I solve this?

  • Post Points: 20
Replied On: Tue, Feb 14 2012 4:53 AM Reply

Hi jcvegan,

 

I would suggest setting an !important declaration of the background property in order this style to override the default style:

 

        .Custom1

        {

            background: #E01B1B !important;

            color: #FFFFFF;   

        }

 

Please let me know if this helps.

Best Regards,
Nikolay
Developer Support Engineer
Infragistics, Inc.
http://www.infragistics.com/support

  • Post Points: 20
jcvegan
Points 420
Replied On: Tue, Feb 14 2012 10:05 AM Reply

Works fine! Thanks... Just another question... when autogenerating the columns on the webdatagrid is there a way to intercept this generation and asign width for each column or some other operations?

  • Post Points: 20
Replied On: Wed, Feb 15 2012 2:09 AM Reply

Hello jcvegan,

 

The columns collection of WebDataGrid does not contain any autogenerated columns. However, you could access and modify such columns client-side. One possible approach would be to handle the Initialize client-side event of the grid. For example:

 

function initializeGrid(sender, args) {

    sender.get_columns().get_column(0).set_width("50px");

}

 

If you have any further questions, please feel free to contact me.

Best Regards,
Nikolay
Developer Support Engineer
Infragistics, Inc.
http://www.infragistics.com/support

  • Post Points: 20
jcvegan
Points 420
Replied On: Wed, Feb 15 2012 8:56 AM Reply

And if I want to fix that generated column?

  • Post Points: 20
Replied On: Thu, Feb 16 2012 2:51 AM Reply

Hi jcvegan,

I'm not sure what you mean by fixing the column. Could you please clarify the question?

Thanks

Best Regards,
Nikolay
Developer Support Engineer
Infragistics, Inc.
http://www.infragistics.com/support

  • Post Points: 20
jcvegan
Points 420
Replied On: Thu, Feb 16 2012 9:09 AM Reply

I wanted to set the columnfixing behavior dynamically by javascript.... but you reply too late I have already done.

function OnInitialize(sender, e) {

            var columnFixing = sender.get_behaviors().get_columnFixing();

           if (columnFixing != null) {

                columnFixing.fixColumnByKey("Mes", $IG.FixLocation.Left);

                columnFixing.fixColumnByKey("DeudaSoles", $IG.FixLocation.Right);

                columnFixing.fixColumnByKey("DeudaDolares", $IG.FixLocation.Right);

            }

}

  • Post Points: 20
Replied On: Thu, Feb 16 2012 9:19 AM Reply

Hello jcvegan,

Thank you for sharing your code with the community.

If you have any other questions, please let me know.

Best Regards,
Nikolay
Developer Support Engineer
Infragistics, Inc.
http://www.infragistics.com/support

  • Post Points: 20
jcvegan
Points 420
Replied On: Thu, Feb 16 2012 2:31 PM Reply

Nikolay is there any way to diplay a tooltip when the mouse pointer is over a cell?

If this is possible, how might it be done?

  • Post Points: 20
Page 1 of 2 (30 items) 1 2 Next > | RSS