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

Process Grid data with Javascript

1 Answer 87 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Rich
Top achievements
Rank 1
Rich asked on 11 Oct 2012, 01:34 PM
I really didn't think this would be that hard.  I've found one other example, but it doesn't seem to work for me.

All  I need to do is, using Javascript on the client side, go through the rows in a data grid, see if the checkbox is check then look at another column in that row to see if it has a value, and then count the checked items.  I know it sounds silly, but we are trying to limit the number of checkboxes actually selected so that everything selected gets printed.  If too many are selected, the reporting tool just doesn't print ANYTHING (I'll save THAT for another post ;~)

Here's the code I have so far:

    function CheckboxCheckedChanged() {
        var grid = document.getElementById('<%= FormView1.FindControl("rgContactsDisplay").ClientID %>');
        var inputElements = grid.get_dataItems();  //THIS IS THE LINE THAT DOESN'T WORK
        var index;
        var MAX = 10;
        var remaining;
        var hldCompany = null;

        for (index = 0; index < inputElements.length; index++) {

              if (inputElements[index].id.indexOf("chkContacts") != -1) {
                if (inputElements[index].checked == true) {
                    // If First row
                    if (hldCompany == null) {
                        hldCompany = grid.rows[index].cells[2]   //grid.row(2);
                    }

                    //If I already have this company, just add 1 for the contact if it’s there
                    if (hldCompany == grid.rows[index].cells[2]) {
                        if (grid.rows[index].cells[3] != null &&
                            grid.rows[index].cells[3] != '&nbsp;') {
                            remaining = remaining + 1;
                            break;
                        }
                    }
                    else {
                        hldCompany = grid.rows[index].cells[2];

                        if (grid.rows[index].cells[3] != null &&
                            grid.rows[index].cells[3] != '&nbsp;') {
                            remaining = remaining + 2;
                            break;
                        }
                        else {
                            remaining = remaining + 1;
                            break;
                        }
                    }
                }
            }
        }

        remaining = MAX - remaining;

        if (remaining < 0) {
            alert("Too many contacts selected for printing");
        }
    }

I've tried a number of different things for the line that doesn't work, but so far the only thing I'm getting is that the "object doesn't support" the method...or errors similar.

I was able to finally get an object from the line above that so I THINK I have a grid to process.

Thanks for any help...

Rich

1 Answer, 1 is accepted

Sort by
0
Andrey
Telerik team
answered on 16 Oct 2012, 08:26 AM
Hello,

Thank you for contacting us.

There are couple of problems with your code:

  • Firs, you are using the getElementById function, instead of $find(). getElementById return the HTML element of the specified control. In this case this will be the DIV element. And as you know the Div element does not have property get_dataItems(). $find() function on other hand returns the JavaScript object which holds all of the client-side functionality of RadGrid.
  • As you could verify from this help topic, get_dataItems() property is a property of RadGrid's MasterTableView object, not of the RadGrid itself.
  • So, in order to get the desired behavior, you need to use the $find() function, then to get the MasterTableView client-side object with the get_masterTableView() function called on RadGrid client-side object. Finally, you could call the get_dataItems() property.

I hope the provided information helps. Let me know if I can assist you any further.


Regards,
Andrey
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
Rich
Top achievements
Rank 1
Answers by
Andrey
Telerik team
Share this question
or