Alpha Software Mobile Development Tools:   Alpha Anywhere    |   Alpha TransForm subscribe to our YouTube Channel  Follow Us on LinkedIn  Follow Us on Twitter  Follow Us on Facebook

Announcement

Collapse

The Alpha Software Forum Participation Guidelines

The Alpha Software Forum is a free forum created for Alpha Software Developer Community to ask for help, exchange ideas, and share solutions. Alpha Software strives to create an environment where all members of the community can feel safe to participate. In order to ensure the Alpha Software Forum is a place where all feel welcome, forum participants are expected to behave as follows:
  • Be professional in your conduct
  • Be kind to others
  • Be constructive when giving feedback
  • Be open to new ideas and suggestions
  • Stay on topic


Be sure all comments and threads you post are respectful. Posts that contain any of the following content will be considered a violation of your agreement as a member of the Alpha Software Forum Community and will be moderated:
  • Spam.
  • Vulgar language.
  • Quotes from private conversations without permission, including pricing and other sales related discussions.
  • Personal attacks, insults, or subtle put-downs.
  • Harassment, bullying, threatening, mocking, shaming, or deriding anyone.
  • Sexist, racist, homophobic, transphobic, ableist, or otherwise discriminatory jokes and language.
  • Sexually explicit or violent material, links, or language.
  • Pirated, hacked, or copyright-infringing material.
  • Encouraging of others to engage in the above behaviors.


If a thread or post is found to contain any of the content outlined above, a moderator may choose to take one of the following actions:
  • Remove the Post or Thread - the content is removed from the forum.
  • Place the User in Moderation - all posts and new threads must be approved by a moderator before they are posted.
  • Temporarily Ban the User - user is banned from forum for a period of time.
  • Permanently Ban the User - user is permanently banned from the forum.


Moderators may also rename posts and threads if they are too generic or do not property reflect the content.

Moderators may move threads if they have been posted in the incorrect forum.

Threads/Posts questioning specific moderator decisions or actions (such as "why was a user banned?") are not allowed and will be removed.

The owners of Alpha Software Corporation (Forum Owner) reserve the right to remove, edit, move, or close any thread for any reason; or ban any forum member without notice, reason, or explanation.

Community members are encouraged to click the "Report Post" icon in the lower left of a given post if they feel the post is in violation of the rules. This will alert the Moderators to take a look.

Alpha Software Corporation may amend the guidelines from time to time and may also vary the procedures it sets out where appropriate in a particular case. Your agreement to comply with the guidelines will be deemed agreement to any changes to it.



Bonus TIPS for Successful Posting

Try a Search First
It is highly recommended that a Search be done on your topic before posting, as many questions have been answered in prior posts. As with any search engine, the shorter the search term, the more "hits" will be returned, but the more specific the search term is, the greater the relevance of those "hits". Searching for "table" might well return every message on the board while "tablesum" would greatly restrict the number of messages returned.

When you do post
First, make sure you are posting your question in the correct forum. For example, if you post an issue regarding Desktop applications on the Mobile & Browser Applications board , not only will your question not be seen by the appropriate audience, it may also be removed or relocated.

The more detail you provide about your problem or question, the more likely someone is to understand your request and be able to help. A sample database with a minimum of records (and its support files, zipped together) will make it much easier to diagnose issues with your application. Screen shots of error messages are especially helpful.

When explaining how to reproduce your problem, please be as detailed as possible. Describe every step, click-by-click and keypress-by-keypress. Otherwise when others try to duplicate your problem, they may do something slightly different and end up with different results.

A note about attachments
You may only attach one file to each message. Attachment file size is limited to 2MB. If you need to include several files, you may do so by zipping them into a single archive.

If you forgot to attach your files to your post, please do NOT create a new thread. Instead, reply to your original message and attach the file there.

When attaching screen shots, it is best to attach an image file (.BMP, .JPG, .GIF, .PNG, etc.) or a zip file of several images, as opposed to a Word document containing the screen shots. Because Word documents are prone to viruses, many message board users will not open your Word file, therefore limiting their ability to help you.

Similarly, if you are uploading a zipped archive, you should simply create a .ZIP file and not a self-extracting .EXE as many users will not run your EXE file.
See more
See less

Easy way to update multiple rows that have been checked...

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Easy way to update multiple rows that have been checked...

    Hello all,

    Can anyone post a solution to easily be able to update multiple records displayed in a grid that have been selected via a checkbox?

    I envision a user clicking multiple rows, then clicking a button that will update the same field for all records to display a value.

    Essentially what I want to be able to select multiple rows in a grid and update a field called UPLOAD STATUS with the value of a userID & timestamp. Basically marking all of the records as being uploaded into a system.

    Please advise.

    Thank you, Casey

  • #2
    Re: Easy way to update multiple rows that have been checked...

    You could try something like this in an ajaxcallback:

    args.xml = e.checkboxFilterArgumentXML
    count = args.count

    for i= 1 to count
    vKeys = vKeys + args[i].data + CRLF()
    next i

    argument_add_array_argument(args,"array_vKeys","c",vKeys)

    sql = "Select Cnt = Count(*) from InvoiceDex where InvoiceDex_ID IN (:array_vKeys)"

    flag = cn.execute(sql, args)

    Comment


    • #3
      Re: Easy way to update multiple rows that have been checked...

      Thank you, however, this is what I was worried about. I'm not formerly trained in Ajax and/or SQL. I was hoping there was some sort of built in function or genie.

      But I will try, can you maybe advise where I can insert the value of what I want to update the multiple records at once.

      Please advise.

      Thanks, Casey

      Comment


      • #4
        Re: Easy way to update multiple rows that have been checked...

        is the userid available in the grid or are you using
        a5.getUserName or session variables?
        thanks for reading

        gandhi

        version 11 3381 - 4096
        mysql backend
        http://www.alphawebprogramming.blogspot.com
        [email protected]
        Skype:[email protected]
        1 914 924 5171

        Comment


        • #5
          Re: Easy way to update multiple rows that have been checked...

          Originally posted by clankford View Post
          Hello all,

          Can anyone post a solution to easily be able to update multiple records displayed in a grid that have been selected via a checkbox?

          I envision a user clicking multiple rows, then clicking a button that will update the same field for all records to display a value.

          Essentially what I want to be able to select multiple rows in a grid and update a field called UPLOAD STATUS with the value of a userID & timestamp. Basically marking all of the records as being uploaded into a system.

          Please advise.

          Thank you, Casey
          Casey,

          I believe you should consider what you need to do, and where you need to do it. Specifically, with reference to your post, you say you want to update a status field to show that the record has been uploaded. Where, when has the upload taken place? Should the record status be updated at the point of the upload? Are the upload and the status field update related?

          I'd also consider updating the status field at the client level. If you make an Ajax Callback to update the status you then may also have to make another callback to refresh the data in your grid. If you update the status field at the client level and then submit the grid, only one callback is needed.

          Comment


          • #6
            Re: Easy way to update multiple rows that have been checked...

            The code above gets you the keys for the IN clause. This code is an example of how you would build the SQL statement.

            args.set("UserId",session.UserID)
            args.set("DateTime",Now())
            args.set("Status","Processed")


            sql = <<%longstring%
            Update [YourTableName] set
            UserID = :UserID,
            DateTime = :DateTime,
            Status = :Status
            where SysID in IN (:array_vKeys)

            %longstring%

            Comment


            • #7
              Re: Easy way to update multiple rows that have been checked...

              Hello David & ghandi,

              I already have the username captured ok using a5.getUserName.

              As far as "upload validation", I do not need for the system to verify the upload status at this point. I just simply want to "flag" the upload status for various customers as "UPLOADED", simply stating that I had taken this list of customers and initiated in another system.

              Thank you, Casey

              Comment


              • #8
                Re: Easy way to update multiple rows that have been checked...

                I already have the username captured ok using a5.getUserName.
                is this a part of the grid, session variable or just available for you to use it in a function?
                thanks for reading

                gandhi

                version 11 3381 - 4096
                mysql backend
                http://www.alphawebprogramming.blogspot.com
                [email protected]
                Skype:[email protected]
                1 914 924 5171

                Comment


                • #9
                  Re: Easy way to update multiple rows that have been checked...

                  Sorry ghandi, it is using a grid....I was planning on capturing via a server side variable?

                  Or even easier, in this particular mass-update I do not necessarily need the username, just would have been nice. Whichever way would be easier.

                  Thanks!

                  -Casey

                  Comment


                  • #10
                    Re: Easy way to update multiple rows that have been checked...

                    Video #90 demonstrates looping through the checked rows in a grid on the client-side:
                    http://www.ajaxvideotutorials.com/V1...ckedValues.swf

                    (If video doesn't come up in IE then try Chrome.)

                    There are some other videos that might be of interest. Go to Help menu in AA, select "Video Finder", enter "check" in the filter box. Skim through the videos looking for "selected", "checkbox" and/or "checked".

                    Comment


                    • #11
                      Re: Easy way to update multiple rows that have been checked...

                      One of the many great (and fun) things about Alpha is the ability to get the same thing done a number of different ways... and have them all be fairly equally efficient. Here are 2 methods for updating a field on a grid based on a checked row. Both are client-side. You update the field and then submit the grid. You can certainly do this server-side, but that means 2 callbacks.

                      Method #1: Using the client-side event onGridRowCheck to build an array of row numbers.

                      First we need to set up a namespace variable... an array we can use to keep track of the rows selected. In onGridRenderComplete...

                      Code:
                      {grid.Object}.__selectedRows = [];
                      Next, in the client-side event onGridRowCheck...

                      Code:
                      var selRows = {grid.Object}.__selectedRows;
                      
                      switch(e.checkboxValue){
                      	case true:
                      		if(selRows.indexOf(e.rowNumber) == -1){
                      			//add to array
                      			selRows.push(e.rowNumber);
                      			{grid.Object}.__selectedRows = selRows;
                      		}
                      		break;
                      	case false:
                      		var selPos = selRows.indexOf(e.rowNumber);
                      		if(selPos > -1){
                      			//remove from array
                      			selRows.splice(selPos,1);
                      			{grid.Object}.__selectedRows = selRows;
                      		}
                      		break;
                      	
                      }
                      Here we grab our namespace variable. This is an array of all checked rows. At first it will be empty, and then when a row is checked our code runs. We determine if we're checking or unchecking, and then add or remove that row from the array. Once done adding or removing we reset the value of our namespace variable.

                      Finally, let's assume you have a Toolbar Action button which updates the field. In the Javascript for this button...

                      Code:
                      var name = {grid.Object}.__currentUserName;
                      var d1 = new Date();
                      d1 = d1.toFormat('MM/dd/yyyy 0h:0m:0s am');
                      var name_stamp = name + ' ' + d1;
                      
                      var selRows = {grid.Object}.__selectedRows;
                      
                      for (var i = 0; i < selRows.length; i++){
                      	{grid.object}.setValue('G', 'APPROVED', selRows[i], name_stamp);
                      }
                      Here we get our current user name (you asked about this in another post). Then we get our namespace variable and loop through that array of values setting values for the appropriate rows.


                      Method #2: Use an Alpha method to get data on all the checked rows... and process that data.

                      In the Toolbar Action button Javascript...

                      Code:
                      var name = {grid.Object}.__currentUserName;
                      var d1 = new Date();
                      d1 = d1.toFormat('MM/dd/yyyy 0h:0m:0s am');
                      var name_stamp = name + ' ' + d1;
                      
                      var checked = {grid.Object}.getCheckedRows();
                      
                      //"checkedRows.key1[]=4&checkedRows.key2[]=11&checkedRows.key3[]=12&checkboxRows.rows[]=1&checkboxRows.rows[]=3&checkboxRows.rows[]=4&checkboxRows.countChecked=3"
                      
                      var checkedRows = {};
                      checkedRows["keys"] = [];
                      checkedRows["rows"] = [];
                      
                      var vars = checked.split('&');
                      var checkedDet = vars[vars.length-1];
                      var checkedArray = checkedDet.split('=');
                      var checkedCnt = parseInt(checkedArray[1]);
                      var pair;
                      var x = 0;
                      
                      for (var i = 0; i < checkedCnt; i++) {
                      	pair = vars[i].split('=');
                      	checkedRows.keys[i] = pair[1];
                      }
                      
                      for (var i = checkedCnt; i < vars.length-1; i++) {
                      	var pair = vars[i].split('=');
                      	checkedRows.rows[x] = pair[1];
                      	x++;
                      }
                      
                      for (var i = 0; i < checkedCnt; i++){
                      	{grid.object}.setValue('G', 'APPROVED', checkedRows.rows[i], name_stamp);
                      }
                      Here we use an Alpha method .getCheckedRows() which returns a string of excellent data about the which rows were checked, the keys for those rows, and the count of checked rows. Chock full of good stuff.

                      Next we process that data into an Object of Arrays. 1 Array for the rows and 1 Array for the keys. We don't really need the keys... but what the heck.

                      Once we have an Array of checked rows... we loop through it assigning a value to the field we want to update.
                      Last edited by Davidk; 11-10-2015, 07:56 PM.

                      Comment


                      • #12
                        Re: Easy way to update multiple rows that have been checked...

                        method #3
                        onGridRowCheck event javascript
                        Code:
                        var name = {grid.Object}.__currentUserName;
                        var d1 = new Date();
                        d1 = d1.toFormat('MM/dd/yyyy 0h:0m:0s am');
                        var name_stamp = 'Updated by '+ name + ' on '+d1;
                        {grid.object}.setValue('G', 'UPLOAD_STATUS', e.rowNumber, name_stamp);
                        the only drawback to this is that every page probably needs to be submitted
                        thanks for reading

                        gandhi

                        version 11 3381 - 4096
                        mysql backend
                        http://www.alphawebprogramming.blogspot.com
                        [email protected]
                        Skype:[email protected]
                        1 914 924 5171

                        Comment


                        • #13
                          Re: Easy way to update multiple rows that have been checked...

                          Nice work David! Thanks for taking the time to share with code samples. I always learn a lot.

                          Comment


                          • #14
                            Re: Easy way to update multiple rows that have been checked...

                            I am able to "change" the value, but I am not sure what is the best method to "Submit" or save the values. How do I commit the changes on multiple records via method 1 using a grid with an editable detail view...
                            NWCOPRO: Nuisance Wildlife Control Software My Application: http://www.nwcopro.com "Without forgetting, we would have no memory at all...now what was I saying?"

                            Comment


                            • #15
                              Re: Easy way to update multiple rows that have been checked...

                              With a detail view your grid part is read-only so changes at the grid level are not possible. You'd have to include code to move to each row, set the detail value, and submit. Which means you're potentially making many callbacks. In this case you're better off doing the updates at the server and refreshing the grid.

                              Comment

                              Working...
                              X