Announcement

Collapse
No announcement yet.

Can you do conditional link on the little pencil icon on a grid?

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

  • Can you do conditional link on the little pencil icon on a grid?

    Hi All,

    I have a grid and it is presently linked to a form and the little pencil sits nicely on the left hand side of the row.

    Can I somehow conditionally send the row to a different form depending on a value in the row?

    In this particular case, I can achieve what I need by adding another grid app, and editing the current grid app, so that they both display just their individual rows. It is just that it would be nice to do it from the one grid.

    Thanks

    Tony

    PS. It seems that sc_link() does not add an icon, only text, otherwise this would work - however, for consistency I need the pencil icon present in the grid.

  • #2
    Your idea with sc_link() is correct and to add an icon is pretty simple.
    Here is the idea.

    onRecord event:

    {your_link_field} = 'path/to/form_app';
    if(something == true)
    {
    {your_link_field} = 'path/to/form_app2';
    }
    sc_link(your_link_field,{your_link_field},,'Edit row');
    {your_link_field} = "<img src='path/to/image.png' />";

    That should do it.

    jsb

    Comment


    • #3
      Thanks, I will give it a try tomorrow morning.

      It seems to make sense when you add the html code, so roll on the morning...

      See ya

      Tony

      Originally posted by jsbinca View Post
      Your idea with sc_link() is correct and to add an icon is pretty simple.
      Here is the idea.

      onRecord event:

      {your_link_field} = 'path/to/form_app';
      if(something == true)
      {
      {your_link_field} = 'path/to/form_app2';
      }
      sc_link(your_link_field,{your_link_field},,'Edit row');
      {your_link_field} = "<img src='path/to/image.png' />";

      That should do it.

      jsb

      Comment


      • #4
        Thanks jsbinca,

        I settled for the code below, but the form does not display the correct record when I click in the link.

        I lodged a support ticket, but thought I would post it here as well -



        I have a grid that contains a number of rows. Each row belongs to one of two "groups" Cash Transactions and Journals. Each is identified by a numeric field.

        I need to be able to edit each row in the grid, but depending on it's type I need to call a different application. So, one application for cash transactions and one for journal entries. Having one link for all rows is not appropriate.

        So in the "On Record" event I have the following code -

        //set up the links for cash v jrnls
        if ({tr_type} == -1){
        {loc_tran_type} = 'Journal';
        sc_link({loc_edit},form_journals.php,{tr_id}={tr_i d},'Edit Journal Entry');
        }else{
        {loc_tran_type} = 'Cash';
        sc_link({loc_edit},form_transactions.php,{tr_id}={ tr_id},'Edit Cash Transaction');
        }

        {loc_edit} is a html image field that shows the pencil icon that is used in other grid applications.

        {tr_id} is the id field, but I am not sure how to pass that value to the form procedure. I do not want to set a global variable as this may well affect other grids from accessing the form. Do you know how best to achieve this?

        If I leave that field out of the macro, it does not display the correct record in the form.

        Thanks

        Tony

        Comment


        • #5
          You have to pass the key as a global variable and you have to give it a different name. i.e. glo_tr_id

          In your form you then use it in the WHERE clause in the SQL section. {tr_id} = [glo_tr_id] //those 'square brackets' defines it as a global variable

          Change your link to:

          sc_link({loc_edit},form_transactions.php,glo_tr_id ={ tr_id},'Edit Cash Transaction');

          That should do it.

          jsb

          Comment


          • #6
            Originally posted by jsbinca View Post
            You have to pass the key as a global variable and you have to give it a different name. i.e. glo_tr_id

            In your form you then use it in the WHERE clause in the SQL section. {tr_id} = [glo_tr_id] //those 'square brackets' defines it as a global variable

            Change your link to:

            sc_link({loc_edit},form_transactions.php,glo_tr_id ={ tr_id},'Edit Cash Transaction');

            That should do it.

            jsb
            Thanks jsb,

            Once again it is bed time for me, but before retiring, and just thinking about it, there are 2 grids that will access the one form, so I suppose I will have to dispense with the standard application link in the second grid and use similar sc_link() coding so that the form's WHERE clause will be the same for both grids.

            Well, I will test it all in the morning.

            Cheers

            Tony

            Comment


            • #7
              Well, you could easily pass a second parameter to identify the application where you are coming from.
              All you have to do is stick your 'where' condition in a global variable as well, so your WHERE section in the form looks like [glo_where], nothing else.

              In the onScriptInit event you check the 2nd parameter and assign the where condition to the variable.

              Code:
              [glo_where] = '1 = 1'; //just to make sure we have a valid expression.
              if([para2] ==1) //call from grid 1
              {
                  [glo_where] = 'tr_id =[glo_tr_id]';
              }
              else
              {
                  [glo_where] = 'some other condition'';
              }
              Good luck

              jsb

              Comment


              • #8
                Originally posted by jsbinca View Post
                Well, you could easily pass a second parameter to identify the application where you are coming from.
                All you have to do is stick your 'where' condition in a global variable as well, so your WHERE section in the form looks like [glo_where], nothing else.

                In the onScriptInit event you check the 2nd parameter and assign the where condition to the variable.

                Code:
                [glo_where] = '1 = 1'; //just to make sure we have a valid expression.
                if([para2] ==1) //call from grid 1
                {
                    [glo_where] = 'tr_id =[glo_tr_id]';
                }
                else
                {
                    [glo_where] = 'some other condition'';
                }
                Good luck

                jsb
                Thanks jsb.

                That could work OK.

                One problem I did have though, when I was testing yesterday, was that I removed the standard application link, thinking it was superfluous, but the effect was that the "ADD" and "SAVE" buttons on the form no longer displayed. If I included the application link then the buttons appeared by then there was a duplication of the "edit" pencil. Maybe I should just dispose of the sc_link() commands and just set the [glo_where_clause] in the on record event.

                I will have to test it again.

                See ya

                Tony
                Last edited by fiscal; 09-03-2015, 11:58 PM.

                Comment

                Working...
                X