Announcement

Collapse
No announcement yet.

merge 2 fields in grid

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

  • merge 2 fields in grid

    hi guys,
    i am wondering if we can merge 2 fields in grid... similar to group date and time in the "same field"... something like showing 2 fields values in one space in grid to save place instead of making them each one with its title in an individual column...

    more info to explain:
    in the form: 10 fields.. if displayed them in a grid, you will have 10 columns...
    2 fields are: classroom name and desk number... so we have in the gird one column that shows the classroom name and the desk number like 5 A6 instead of having classroom 5 and desk number A6

    i saw the group label thing, this is nice, but also doesn't remove the column between 2 fields... but adds extra titles that can combine more columns...

    any idea?

  • #2
    Hi,
    the CONCAT functioin is your friend. Use it in your sql statement of your grid.

    SELECT CONCAT(classroom,' ',desk) as Desk, ... From ...

    jsb

    Comment


    • #3
      oh, i though to hide the fields then use a virtual field from sc and put in the new field something like {classroom} {desk} but didn't actually work as required..


      well, where to put that concat statement? i mean not to include the 2 fields in the grid? and instead, i have to use this in the main sql of the grid of SC?


      one more Q for you boss, not relate to this: remember u helped me earlier in the multiple records form to make the fields disabled/change colors using javascript methods.. all works fine, but because i have around 7 java script methods in each sc application, can't be used in libraries instead? they have the counter parameter "row_cnt" add to js method "row_nr" hope u remember this one.. i tried to use it as libaray but couldn't because there is no place to add the parameter "row_nr" as it is in javascript method.... this is just because i will use it in all applications so it will be easier to use it as function jsmethod(); in events and ajax events.. is it applicable or i have to copy the methods to all applications as used to do?

      Comment


      • #4
        Yes, the CONCAT function has to be used in the sql statement for your grid.

        You can copy your javascript functions in a .js file and save it within your project's folder structure (_lib folder is probably a good place).
        In the onApplicationInit of your app just do a

        echo "<script type='text/javascript' src='mylibrary.js'></script>";

        You can then call your js functions like any other function.

        jsb

        Comment


        • #5
          Dude, life saver, thanks a lot

          Comment


          • #6
            One remark: do *not* store your js files somewhere in the _lib directory. The main reason is that on every SC update the full directory is lost and rebuild causing your files to disappear...
            Albert Drent
            aducom software netherlands
            scriptcase partner, reseller, support and (turn-key) development
            www.scriptcase.eu / www.scriptcase.nl

            Comment


            • #7
              yes Albert, thanks, i was thinking to create library folder other than _lib but anyway i am stuck in one of the javascript methods so i can't do that unless first works fine in the normal methods place.. then will try move them into a folder as js files...

              Comment


              • #8
                okayyyy, as this works now finally

                A- i have around 8 js methods, should i create one js file for each one and then add all this to onAppInit? or just one having all of them?

                assuming i will add new forlder for these js files in the same level of the _lib folder... projectFolder/mylib/jsfile.js...

                echo "<script type='text/javascript' src='mylib/method1.js'></script>";
                echo "<script type='text/javascript' src='mylib/method2.js'></script>";
                echo "<script type='text/javascript' src='mylib/method3.js'></script>";
                echo "<script type='text/javascript' src='mylib/method4.js'></script>";
                echo "<script type='text/javascript' src='mylib/method5.js'></script>";
                echo "<script type='text/javascript' src='mylib/method6.js'></script>";
                echo "<script type='text/javascript' src='mylib/method7.js'></script>";
                echo "<script type='text/javascript' src='mylib/method8.js'></script>";

                B then what to put in the js file? only this

                Code:
                sc_ajax_javascript('js_fieldfield2color',arr ay({ row_cnt}));
                or all the function with the condition:

                Code:
                If ({df} == '0')
                sc_ajax_javascript('js_fieldfield2color',arr ay({ row_cnt}));
                as i am happy because that other stupid little issue was solved... this isn't so important.. just because all the applications will have this js methods and they are 8 so though to put them in a library as you guys teach me to do with php libraries... if will waste your time to explain or is complicated and not advised, please ignore

                cheeers

                Comment


                • #9
                  What you have here is all php stuff. The javascript function would be 'js_fieldfield2color'.
                  The code from there would have to be in your library together with all the other functions you call with the sc_ajax_javascript macro.
                  i.e.
                  //myjslib.js

                  function js_fieldfield2color(row)
                  {
                  ...
                  }

                  function js_field_disable(row)
                  {
                  ...
                  }

                  //end of myjslib.js


                  In my opinion, I don't think you gain very much. As far as I remember your are using the js stuff to set a field colour and/or disable/enable it.
                  Why don't try to improve the js functions to that effect that you call only one function that does it all and pass a set of parameters.

                  i.e.
                  sc_ajax_javascript('js_set_my_field',array($fieldn ame, $row, $colour, $status) );

                  Just a thought.

                  jsb

                  Comment


                  • #10
                    hi Jsb, that's above my limit dude, although it is perfect idea to combine them but not yet advanced enough to make it work, i guess will go with the available methods for now, they are 8 and repeated in all applications.. will copy them (i usually copy the application itself and modify it to have the other one and so on).. disadvantage is that if something changes, i will need to go through all of them again, will leave with that

                    so happy to see you around, feeling like confidence

                    cheers

                    Comment

                    Working...
                    X