Example: Updating a Grid Cell programatically

  1. #1

    Example: Updating a Grid Cell programatically

    hi,

    very happy with coolite. Lets grow the sample code base.

    Lets say you have a grid and on each row (record) there is a field (cell) that represents the sum total of a few of the other cells. We'll call that field total. Here is an easy way to do it.

    Add a Listener to your grid:

    <Listeners> 
      <ValidateEdit Fn="calcTlt" /> 
    </Listeners>
    On each row click you are going to get an event back with the EventArgObject.

    var calcTlt = function(e) {
    
        var val = parseFloat(e.value);   // this is the value of the current changed field ...
        var valOfTlt = parseFloat(e.record.get('Tlt')); // Tlt is the name of the field i want to update
        var setTo = valOfTlt + val;
        e.record.set('Tlt', setTo);
    
    };
  2. #2

    RE: Example: Updating a Grid Cell programatically

    Following up with some simple modifications that make this work better:

    1) Use "AfterEdit" this lets the control value get set

    <Listeners>
                <CellClick Fn="cellClick" />
                <AfterEdit Fn="calcTlt" />
    </Listeners>
    2) This javascript now calcs the total on the set values in the cells.

    var calcTlt = function(e) {
        var arrayOfGetLines = new Array('Mon', 'Tu', 'Wed', 'Th', 'Fri', 'Sat', 'Sun');
        var iTlt = 0;
        for (var l in arrayOfGetLines) {
            var line = arrayOfGetLines[l];
            var valOf = parseFloat(e.record.get(line));
            if (valOf.toString() != 'NaN') {
                iTlt += valOf;
            }
        }
        
        e.record.set('Tlt', iTlt);
    };

Similar Threads

  1. [CLOSED] updating a grid's cell not working
    By Fahd in forum 2.x Legacy Premium Help
    Replies: 4
    Last Post: Jul 23, 2012, 9:09 PM
  2. How to set Grid Panel's css when updating
    By alleusai in forum 2.x Help
    Replies: 0
    Last Post: Jul 03, 2012, 2:39 PM
  3. [CLOSED] Updating grid row values
    By Pablo_Azevedo in forum 1.x Legacy Premium Help
    Replies: 1
    Last Post: Sep 24, 2010, 1:31 PM
  4. [CLOSED] Updating DateField in Grid (on clientside)
    By pschojer in forum 1.x Legacy Premium Help
    Replies: 1
    Last Post: Jul 20, 2009, 6:21 AM
  5. Problem with updating grid panel
    By Nagaraj K Hebbar in forum 1.x Help
    Replies: 0
    Last Post: May 09, 2009, 12:52 PM

Posting Permissions