Page 2 of 2 FirstFirst 12
Results 11 to 17 of 17

Thread: How I can open a webpage from one or more rows selected in a gridpanel?

  1. #11
    Sencha Premium User jvandemerwe's Avatar
    Join Date
    Apr 2009
    Location
    Raalte, Netherlands
    Posts
    249

    Default

    What exactly are you trying to achieve?

    And remember if you change the fiddle from ExtJS 4 to ExtJS 5, change the Ext.appyIf in the grid to Ext.apply.

    How exactly should the links be opened in the browser? Now they opening in seperate tabs.

    And I woud consider to change your code a little (don't use xx as fieldname, use something that makes sense):

    PHP Code:
    me.on('ButtonClicked', function (grid) {  
          var 
    sm grid.getSelectionModel(); 
          var 
    selected sm.getSelection();

          var 
    numRecords sm.getCount(); // Devuelve el nmero de filas seleccionadas

          
    if (numRecords === 1) {
     
               
    Ext.each(selected, function(item) { 
                    var 
    url item.get('Archivo');
                    
    window.open(url);
               }, 
    this);

          } else if (
    numRecords 1) {

               
    Ext.each(selected, function(item) {
                    var 
    url sm.selected.items[i].raw.Archivo// not in your model??? 
                    //var url = item.get('Archivo'); 
                    
    window.open(url);
               }, 
    this);

          } else {

              
    Ext.Msg.alert('Error','Debe seleccionar al menos un archivo');        

          }

    }, 
    me); 
    And I am a little puzzled about: sm.selected.items[i].raw.Archivo;
    Is "Archivo" not in your model definition? Otherwise you can use item.get('Archivo');

    What is exactly the difference between the 1 record clause and the more than 1 record clause in the "if" statement? It looks that it does exactly the same.

    Quote Originally Posted by sesebas View Post
    Hi,
    Finally I could work and adapt this code (https://fiddle.sencha.com/#fiddle/o1l) for my project, but I need you if you have selected more than one link, each open after the other, in one page html.


    This is my code so far:

    Code:
          me.callParent(arguments);
    
    
          me.on('ButtonClicked', function (grid) {
             
              var sm = grid.getSelectionModel(); 
              var selected = sm.getSelection();
    
    
          var xx = sm.getCount(); // Devuelve el nmero de filas seleccionadas
          
          for (i = 0; i < xx; i++) {
    
    
                var itm = sm.selected.items[i];
    
    
                console.log(itm, "i vale: ", i); // para debug
    
    
                    if (i < 1){
                        Ext.each(selected, function(item) {
                         var url = sm.selected.items[i].raw.Archivo;
                         window.open(url);
                        }, this);
    
    
                      } else if (i >= 1 ) {
    
    
                        Ext.each(selected, function(item) {
                         var url = sm.selected.items[i].raw.Archivo;
                         //var url = item.get('Archivo');
                         window.open(url);
                        }, this);
    
    
                      } else {
    
    
                        Ext.Msg.alert('Error','Debe seleccionar al menos un archivo');
                      }
    
    
                      
            }
    
          }, me);
    Imagen:

    Attachment 52681

  2. #12
    Sencha User
    Join Date
    Aug 2013
    Posts
    20

    Default

    Dear jvandemerwe,


    Thanks for your time, patience and help.The end result hopefully get at this early stage of my project you can see in the picture below:If the user selects more than one link, then ...
    EndResult.jpg

    The origin of this comes from another project developed some time ago, but as it works well, I wanted to migrate to ExtJs 4 ...

    Original project (you can see in "http://celade.cepal.org/piaalc_esp/MIGR_Int/SelectS.php"):
    OriginalProject.jpg

    Sections "A" and "B" are ready and work well from my treePanel in ExtJs4, but I must run the equivalent of "C" section adapting the sencha code that you suggested me and enable buttons to "open in new tab" and "download".

    Short answers:
    [I]And I am a little puzzled about: sm.selected.items.raw.Archivo;
    [I]Is "Archivo" not in your model definition? Otherwise you can use item.get('Archivo');

    "File" is the definition of my model ... and the change did because he played with the debug and found I could use the result of "sm.getCount ()" to control the links that can open (both "sm .selected.items .raw.Archivo "and "Item.get ('File')" return the same to me.

    What is exactly the difference between the 1 record clause and the more than 1 record clause in the "if" statement? It looks that it does exactly the same.

    As you can see, there are no differences in the clause "if". I figured that if only one link is selected, then only works the first part of "if", but if are two or more links selected, then the first part of "if" opens the first link and could keep the focus on that page to open the following URLs one after another ... but not how to do this.

    Thank's for your support

  3. #13
    Sencha Premium User jvandemerwe's Avatar
    Join Date
    Apr 2009
    Location
    Raalte, Netherlands
    Posts
    249

    Default

    Now I see what you mean. And the URL's that you want to open are they already existing (that means, can they be opened also by putting the URL in the browser)?

    You can do this with Ajax. What you do is that you send the URL's in an Ajax call to the server where you have a php script receiving the url's that you want to "merge" into a single page. So you don't open immediately the URL's, but you process them first on the server.

    In that process you iterate the URL's and collect the content of the URL's ($fget, I believe). Then you build the html page and as a string where you put everything together. Then you send the total page you have build (htmlencode it first) back as result of the Ajax call and the callback of the Ajax call opens the tab presenting the result that you have built on the server. See example below.

    Code:
    var myWindow = window.open("", "MsgWindow", "width=200, height=100");
    myWindow.document.write("<p>This is 'MsgWindow'. I am 200px wide and 100px tall!</p>");
    With this as result:

    SH_014466.jpg

    If you have an Ext application with a viewport you can also return the results you have built in an Ext.Window (which is more consistant with the "app" feeling).

    I

  4. #14
    Sencha Premium User jvandemerwe's Avatar
    Join Date
    Apr 2009
    Location
    Raalte, Netherlands
    Posts
    249

    Default

    Small remark to "selected.items.raw.Archivo" versus "item.get("Archivo"). With the first one you handpick the data directly from the object and with the "item.get" you are using a function which is supported by the Ext JS framework. The "item.get" is always better to use, because when Sencha decides to change the framework conventions and put the data that you now have handpicked somewhere else in the object, your program will fail to function in finding that data. I always use the function that is offered by Sencha rather than "handpick" myself from the object. It is better to trust the API documentation then the outcome of the debugger of your browser.

    Quote Originally Posted by sesebas View Post
    Dear jvandemerwe,


    Thanks for your time, patience and help.The end result hopefully get at this early stage of my project you can see in the picture below:If the user selects more than one link, then ...
    EndResult.jpg

    The origin of this comes from another project developed some time ago, but as it works well, I wanted to migrate to ExtJs 4 ...

    Original project (you can see in "http://celade.cepal.org/piaalc_esp/MIGR_Int/SelectS.php"):
    OriginalProject.jpg

    Sections "A" and "B" are ready and work well from my treePanel in ExtJs4, but I must run the equivalent of "C" section adapting the sencha code that you suggested me and enable buttons to "open in new tab" and "download".

    Short answers:
    [I]And I am a little puzzled about: sm.selected.items.raw.Archivo;
    [I]Is "Archivo" not in your model definition? Otherwise you can use item.get('Archivo');

    "File" is the definition of my model ... and the change did because he played with the debug and found I could use the result of "sm.getCount ()" to control the links that can open (both "sm .selected.items .raw.Archivo "and "Item.get ('File')" return the same to me.

    What is exactly the difference between the 1 record clause and the more than 1 record clause in the "if" statement? It looks that it does exactly the same.

    As you can see, there are no differences in the clause "if". I figured that if only one link is selected, then only works the first part of "if", but if are two or more links selected, then the first part of "if" opens the first link and could keep the focus on that page to open the following URLs one after another ... but not how to do this.

    Thank's for your support

  5. #15
    Sencha User
    Join Date
    Aug 2013
    Posts
    20

    Default

    Thank's, I will review what you just sent me.


    In fact, in the original application I used a call to "recibeS.php" that was responsible for building the page response to the content of one or more user-selected links ... my problem is that I have not known how to send , from the client, the variable / array containing the user-selected links ... "numRecords" returns me the number of rows / selected links, but do not tell me the contents of the field "File" to be required in the process server.


    This is the code in "recibeS.php" (I have not used now)

    Code:
    <html>
    <head>
        <title>Sitio CELADE-PIAALC - Migracin Interna</title>
    </head>
    
    
    <body>
    </body>
    
    
    <?php
        ECHO "<a href='$rows'><div align=center><img src='SaveFile.PNG' border=0></div></a> <br /><br />";
    foreach( $_POST[rows] as $value )
    {
        include $value;
    
    
        $save  = trim($value);
        $save1 = explode("htm",$save);
        $save2 = $save1[0].'xls';
        $save3 = str_replace("IE","Otro",$save2);
    
    
        ECHO "<a href='$rows'><div align=center><img src='SaveFile.PNG' border=0></div></a> <br /><br />";
    }
    
    
    ?>
    
    
    </html>

  6. #16
    Sencha Premium User jvandemerwe's Avatar
    Join Date
    Apr 2009
    Location
    Raalte, Netherlands
    Posts
    249

    Default

    See this article I wrote last year on how to post an array with Ext.Ajax to the server. http://www.enovision.net/snippets/it...-ajax-request/

    Quote Originally Posted by jvandemerwe View Post
    Small remark to "selected.items.raw.Archivo" versus "item.get("Archivo"). With the first one you handpick the data directly from the object and with the "item.get" you are using a function which is supported by the Ext JS framework. The "item.get" is always better to use, because when Sencha decides to change the framework conventions and put the data that you now have handpicked somewhere else in the object, your program will fail to function in finding that data. I always use the function that is offered by Sencha rather than "handpick" myself from the object. It is better to trust the API documentation then the outcome of the debugger of your browser.

  7. #17
    Sencha User
    Join Date
    Aug 2013
    Posts
    20

    Default

    Hello Dear (s),


    Finally I could go a little further to display all selected links on a single page ... but now I can not do that "recibeS.php" opens in the browser, I can only see it in the debugger / Network and the line:
    Code:
    ECHO "<a href='$value'><div align=center><img src='SaveFile.PNG' border=0></div></a> <br /><br />";
    dont work.

    My js code:
    Code:
          me.on('ButtonClicked', function (grid) {
             
              var sm = grid.getSelectionModel(); 
              var selected = sm.getSelection();
              var numRecords = sm.getCount(); // Devuelve el nmero de filas seleccionadas
     
            Ext.each(selected, function(item) {
                var url = item.get('Archivo');
                rows.push(url); // agrega enlaces a la matriz
            }, this);
     
            Ext.Ajax.request({
            url: 'recibeS.php',  // mi url
            method: 'POST',
            params: {
     
                  'group[]': rows,  // incluye la matriz en los parmetros
    
    
                  ///////// One of my attempts... Dont work... ///////
                  success: function(result, action) {
                  var win =Ext.getCmp('myCmp');
                  win.myWindow.show();
                  }
                  //////////////////////////////////////////////////////////////////////
              },
          })
     
          }, this);
       }
    
    
    })
    My Php code:

    Code:
    <html>
    <head>
        <title>Aplicacin de prueba - Despliege de tabulados</title>
    </head>
     
    <body>
    
    
    </body>
     
      <?php
     
     foreach( $_POST['group'] as $value){
      
          include $value;
          ECHO "<a href='$value'><div align=center><img src='SaveFile.PNG' border=0></div></a> <br /><br />";
    
    
    }
    
    
    ?>
     
    </html>
    I can only see it in the debugger / Network...

Page 2 of 2 FirstFirst 12

Similar Threads

  1. Keep rows selected in GridPanel
    By payo22 in forum Ext 3.x: Help & Discussion
    Replies: 2
    Last Post: 8 Mar 2013, 7:40 AM
  2. Gridpanel rows getting selected via keyboard in Firefox.
    By Addil in forum Ext 3.x: Help & Discussion
    Replies: 0
    Last Post: 4 Feb 2011, 3:48 AM
  3. [3.0.0] GridPanel - new rows stay permanently selected
    By stachobywatelpl in forum Ext 3.x: Help & Discussion
    Replies: 3
    Last Post: 26 Feb 2010, 12:54 AM
  4. [ HELP ! ] GridPanel -> How to get selected rows ids
    By merianos in forum Ext 3.x: Help & Discussion
    Replies: 1
    Last Post: 17 Dec 2009, 3:59 AM
  5. GridPanel, how to know what rows have been selected?
    By jimtyp in forum Ext 3.x: Help & Discussion
    Replies: 1
    Last Post: 25 Aug 2009, 12:45 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •