Announcement

Collapse
No announcement yet.

How add an input field to a grid...

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

  • How add an input field to a grid...

    Hi all,

    I got a grid that display all products/items with specific unit price for each customer (login user = customer).

    I need to add a column to the end of grid where to insert a quantity value. Being a grid I think it's not possible.
    Then based on two icons 'Order' or 'RFQ' I've to take that quantity and insert/update data in other connected tables.

    How can I achieve this ? Is there any workaround ?
    Attached Files

  • #2
    In a standard grid you cannot add fields. If you need that then you need to create a multiple record form.
    Albert Drent
    aducom software netherlands
    scriptcase partner, reseller, support and (turn-key) development
    www.scriptcase.eu / www.scriptcase.nl

    Comment


    • #3
      Hi Albert,
      As you suggested , I'm using a form editable gridview. I added to table the Quantity field but only for make an input.
      Now I got several rows where the only updatable field is Quantity (column) .
      Once the user insert the quantity of that specific item line, later, I want to use two icons fields and OnClick event to trasfert that quantity to another table.

      Becouse the table is like a item catalogs I want to inhibit the possibility to use the two Icons in front of every row (update arrows, delete bin).

      How can I hide them ?? Need I to create a new theme... or something like that... ;-(
      Do you think that form works the same... without the two initial icons ??

      Thanks

      Comment


      • #4
        Hi, giovannino,

        here is a live example of SC form (editable grid) where you can edit quantity.
        as you can see there is no icons on the left side of each row only the input.

        Attached Files
        Best Regards
        Hiram BQ

        Comment


        • #5
          I have to use a form..... editable grid instead .. ;-(

          Hi Hiran, thank for support.
          It seems that only possible solution is about using a form editable grid disabling all field but the Quantity field.
          Quantity is a fictious field added to Products table (item catalogue) in order to have an input field.
          The Htlm image are then linked to a blank application that run the insert/update code to another table (i.e. insert/update Orders_details table or RFQs_details table).
          In your sample it seems that you update your same table or delete the row (I suppose but I'm not sure)
          Lets look to my image... no alternative ways at the moment.

          Do you know how hide initial icons of the form ?? I mean deleting bin and update arrows ? I can leave to user to delete a row becouse it's a catalogue item row...
          It has to remain for all other user that maybe would like to order that item...
          Attached Files

          Comment


          • #6
            Hi Giovannino,
            1. To hide icons can use the SC security module MODULES->SECURITY and disable for that user add, edit, delete or you can use CUSTOM CSS to hide the control
            2. You can place all you want on each row, that means custom buttons, controls, images, text etc.
            For example if you need field quantity, just add a custom field in the form FORM SETTINGS->Fields -> new field
            To update you other table just add an ajax event: FORM SETTINGS->Ajax events and select ONCHANGE for your quantity field
            Best Regards
            Hiram BQ

            Comment


            • #7
              Hi Hiram, thanks.
              If you use a grid you can't have an input field like Quantity within others. Grid only display as default. That's why I needed to change to form.
              About rows you can add almost all fields type but when you have to use OnClick Ajax events only some of them works (i.e. Html image not works) .
              The only way to add code to a Htlm Image is to redir it after click with link to a blank application, run the code and then come back to form again... ;-(
              The ugly thing is that all screen become white for a while (becouse of linked blank application running ) and then it comes back to form.
              Is there a way to run the code without seeing the White page screen ??
              Bye

              Comment


              • #8
                How to add input fields on a Grid using SC and call a javascript function

                In this example we are going to call a javascript funcion when user write a value on the custom field

                1. First add a Text field with Show HTML content OFF and name it col on your Grid App then add OnRecord:
                {col}= "<input type='text' onkeyup='myfunction({id},this.value)'>";

                Note: {id} must be your table id field, so you can identify the new quantity value for that id

                2. onHeader of your grid write thiscode:

                Code:
                echo '<script>
                function myfunction(id,quantity){
                    alert("ID:"+id + " and quantity:"+quantity); // place your CUSTOM CODE HERE
                }
                </script>';

                On this step you must place your custom JAVASCRIPT code, and thats all now you know the ID and the new quantity.


                ============================================

                Assuming that you know about how to implement AJAX, just replace the code to send that ID and quantity to a PHP file or SC blank app

                Code:
                echo '<script>
                function myfunction(id,quantity){
                $.post( "yourFile.php", { "id": id, "quantity": quantity })
                
                  .done(function( data ) {
                    alert( "Response of yourFile.php: " + data );
                  });
                }
                </script>';
                Replace yourFile.php with the real URL of your PHP file ( or SC blank app).
                On yourFile.php you can use $_POST['id'] to get the ID and $_POST['quantity'] to get the quantity and run a MySQL query to update a table
                Last edited by hirambq; 12-31-2014, 10:13 PM.
                Best Regards
                Hiram BQ

                Comment


                • #9
                  Hi Hiram, thanks

                  I implement first part of your suggestion and it seems it can work.
                  On second part when you say "you can also add javascript event onChange for example:" I got a problem becouse the only available selection given is only OnClick.
                  Is it only an alternative or I need also implement it ?

                  When you say "also can use AJAX to update values on the fly." what do you mean ?

                  Have you got a sintax sample just to understand how write it ?
                  Attached Files

                  Comment


                  • #10
                    Hi Hiram,
                    Now I got this within OnRecord code.
                    {Quantity}="<input type='text' size='6'>"; If I'm not wrong this show only the field as data input . If I do echo {Quantity} I see only the field as rectangle not the value on it.

                    I need to have the possibility to use the value that user insert into it on data entry.
                    How can I do ? The only option open on Ajax Events is "OnClick" , but I insert a value I don't click it. The OnChange it could be nice but it's not available.


                    When I used the form I did something like that within Quantity_onChange (that was open on dd list).

                    [glo_Quantity_row]={Quantity};

                    in order to have later the possibility to use the Quantity value in othen applications called.
                    When I later do the insert on mysql DB I need to have quantity value available as global variable.

                    Many thanks

                    Comment


                    • #11
                      How to add input fields on a Grid using SC and call a javascript function

                      In this example we are going to call a javascript funcion when user write a value on the custom field

                      1. First add a Text field with Show HTML content OFF and name it col on your Grid App then add OnRecord:
                      {col}= "<input type='text' onkeyup='myfunction({id},this.value)'>";

                      Note: {id} must be your table id field, so you can identify the new quantity value for that id

                      2. onHeader of your grid write thiscode:

                      Code:
                      echo '<script>
                      function myfunction(id,quantity){
                          alert("ID:"+id + " and quantity:"+quantity); // place your CUSTOM CODE HERE
                      }
                      </script>';

                      On this step you must place your custom JAVASCRIPT code, and thats all now you know the ID and the new quantity.


                      ============================================

                      Assuming that you know about how to implement AJAX, just replace the code to send that ID and quantity to a PHP file or SC blank app

                      Code:
                      echo '<script>
                      function myfunction(id,quantity){
                      $.post( "yourFile.php", { "id": id, "quantity": quantity })
                      
                        .done(function( data ) {
                          alert( "Response of yourFile.php: " + data );
                        });
                      }
                      </script>';
                      Replace yourFile.php with the real URL of your PHP file ( or SC blank app).
                      On yourFile.php you can use $_POST['id'] to get the ID and $_POST['quantity'] to get the quantity and run a MySQL query to update a table
                      Best Regards
                      Hiram BQ

                      Comment


                      • #12
                        Ok Thanks.

                        I did first part but I did change 'onkeyup' with 'onchange' becouse when I started to write the quantity value, it popup eveytime suddenly. I hope it could be ok the same.
                        I used ProductID instead of id becouse I got it . It's a text field . I hope that is not a problem but as you can see on attached images I got some problems on header alert message.

                        Then onHeader I inserted the code as you suggested.

                        Now the last part is not clear to me.
                        That code has to be placed on Header too or into OnRecord . I got a blank code application I used on form to make the insert of the row values and quantity on mysql table "products_selected".
                        When I did it I got all global variables coming from the link connected to image icon "Order" . I suppose I have to map them all too here.
                        Unfortunately I'm not a programmer and so it's almost complicated for me... to understand all steps ;-(
                        Attached Files
                        Last edited by giovannino; 01-01-2015, 09:08 AM.

                        Comment


                        • #13
                          if you are going to use ajax you must use the code of step 3 onHeader. (The code on step 2 is just an example to see the values)

                          The code on step 3 send two values to another URL you need to do something with that values like run a SQL query.
                          - You cant use a SC form to send that values needs to be a SC blank app and run your SQL query
                          Last edited by hirambq; 01-02-2015, 03:45 AM.
                          Best Regards
                          Hiram BQ

                          Comment


                          • #14
                            On step1 i got : {col}= "<input type='text' size='6' onchange='myfunction({ProductID},this.value)'>";

                            the alert later give me a wrong value for {ProductID} . I also try to use '{ProductID}' between quotes but it give an error. SEE IMAGE

                            Why alert work only on first row and then, on other rows, not ??

                            echo '<script>
                            function myfunction(id,quantity){
                            alert("ID: "+id + " and quantity: "+quantity); // place your CUSTOM CODE HERE
                            }
                            </script>';

                            If I have 7/8 parameters to pass to blank application where I have to add them ?

                            This is the blank with all glo_variables I need to record the row into table. ProductID and Quantity are some of them.

                            [order_date] = date('Y-m-d');

                            $sql_insert_selected = "
                            INSERT products_selected
                            (ProductID, CustomerID, ProductName, SupplierID, CategoryID, CompanyID, SelectedDate, Quantity, UnitPrice , ProductID_altern)
                            VALUES
                            ('[glo_ProductID]', '[glo_CustomerID]', '[glo_ProductName]', '[glo_SupplierID]' ,
                            '[glo_CategoryID]', '[glo_CompanyID]', '[order_date]' , [glo_Quantity_row], [glo_UnitPrice], '')
                            ON DUPLICATE KEY UPDATE Quantity = Quantity + [glo_Quantity_row]";

                            sc_exec_sql( $sql_insert_selected );
                            sc_redir(hhh_grid_products_for_order, "", "_parent");
                            Attached Files

                            Comment


                            • #15
                              If your ProducID is not numeric needs be in quotes like this:

                              Code:
                              {col}= "<input type='text' size='6' onchange='myfunction(\"{ProductID}\",this.value)'>";
                              If you need to send more parameters then, just add a comma inside the function and ,\"{VAR1}\"

                              Code:
                              {col}= "<input type='text' size='6' onchange='myfunction(\"{ProductID}\",this.value,\"{VAR1}\")'>";
                              
                              Then change your javascript function for each extra parameter
                              Code:
                              echo '<script>
                              function myfunction(id,quantity,var1){
                              alert("ID: "+id + " and quantity: "+quantity +"var1:"+var1); // place your CUSTOM CODE HERE
                              }
                              </script>';
                              
                              
                              Please note that this javascript code only shows the values dont send any data to your Blank app
                              Best Regards
                              Hiram BQ

                              Comment

                              Working...
                              X