Announcement

Collapse
No announcement yet.

Delete only latest raw

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

  • Delete only latest raw

    Hi All,
    I have Master details form, i want to give the user ability to delete only the latest record.
    what i mean is to show the delete icon at the latest raw only and if he delete it, it will show at the previous raw only and so.

    is it Possible with scriptcase ?

    i am attaching photo to understand more what i am trying to get

    Master.jpg

    Thanks in advanced

    Best regards

  • #2
    You can, but you have to do it playing with JavaScript I think, never tried something like this
    /Giuseppe

    Professional Scriptcase Services
    Some Customers opinions

    Comment


    • #3
      try MAX with LIMIT 1 in SQL

      Comment


      • #4
        Thank you Mike,
        if you mean to put it from the start in sql
        this will bring only 1 record , what i want is to bring all the data on screen, but limit the user to delete only the latest record from latest then previous.

        it is very importing to do that because the latest record calculation is based on the previous record, and if the user delete somewhere in the start or middle, everything will be wrong!!

        did anyone try to get this before ? any hints ?

        regards
        Last edited by walid; 04-05-2015, 09:50 AM.

        Comment


        • #5
          Originally posted by Giu View Post
          You can, but you have to do it playing with JavaScript I think, never tried something like this
          Thank you Giu,
          the problem that i am not expert in JavaScript, if you manage to try something like this, please send me

          Best regards

          Comment


          • #6
            here is a new photo explain what i am trying to get

            delete.png


            regards

            Comment


            • #7
              Originally posted by walid View Post
              here is a new photo explain what i am trying to get

              [ATTACH=CONFIG]2016[/ATTACH]


              regards
              Oops, you mean only the icons (the functionality), not the whole records! plz ignore my previous reply then, lets try to think differently.

              Will get back to you.

              Comment


              • #8
                hi,
                anyone knows how to do this ?

                Regards,

                Comment


                • #9
                  Ok - you can do it this way (see picture for how this looks)...

                  Capture.jpg

                  First add a field, e.g. "delete" of type HTML Image. Leave everything else as default (and the image field blank). In Field Positioning move the "delete" field to the top.

                  Then in the grid's onScriptInit:

                  Code:
                  $sqlq = "SELECT COUNT(*) FROM tblxxxxxxx WHERE xxxxxx";        // Duplicate the grid's overall query with relevant WHEREs etc to get the grid's record count
                  
                  sc_lookup(my_data, $sqlq);
                  
                  if ({my_data} === false) {
                  	echo "<script type='text/javascript'>alert('DB Access error. Message = " . 
                  		{my_data_erro} . "');</script>";
                  	[last_record] = 0;
                  
                  } else {
                  	[last_record] = {my_data[0][0]};
                  }
                  
                  [rec_pos] = 0;
                  Make sure, after saving the app, to set the 2 global variables (rec_pos and last_record) just defined above in Application => Global Variables as type "out".

                  Then in onRecord:

                  Code:
                  [rec_pos] += 1;
                  
                  if ( [rec_pos] == [last_record] ) {		// if last record only
                  	{delete} = "<img src='../_lib/img/scriptcase__NM__ico__NM__trash.gif' alt='Delete' title='Delete' >";     // Assign "trash" image to just that record
                  } else {
                  	{delete} = '';
                  }
                  Now create an Ajax event for the "delete" field of type onClick. Select the key / id field to pass as a parameter. In the code window enter the code you want processed, i.e. delete that record. To test the functionality I used below (but you will need to add your own PHP delete code for the record - can't do it ALL for you ):

                  Code:
                  echo "hello " . {fffffff};    // ffffff = a visible field name
                  Now, if the grid is paginated (which is the default) and your last record is not on the first screen it doesn't work (for some reason) - not sure why and not had the time to look into it. To get around this though, turn off pagination (in Grid Modules, click on Grid on the right and set pagination to Total) - but again, I'll leave it to you to tweak it t work with pagination if it's needed.

                  That's it.

                  Comment


                  • #10
                    Thanks alot adz1111 ,

                    i will try to do it like you explain.

                    i will come with updates once done

                    regards

                    Comment


                    • #11
                      Hi adz1111 ,
                      to get the last record always on the first screen, ORDER BY id DESC.
                      now what i am getting when running only text <img src='../_lib/img/scriptcase__NM__ico__NM__trash.gif' alt='Delete' title='Delete' > , when moving to next page and come back to the first page Trash icon appear and the text disappear !!!

                      see photo 1 and photo 2
                      1.png2.png


                      more details :
                      i am not using a grid
                      i am using a master form with details form (orientation set to Editable grid view).
                      any idea how to fix this ?
                      thanks in advanced
                      Last edited by walid; 04-27-2015, 05:28 PM. Reason: adding photo

                      Comment


                      • #12
                        I'll have a look when I can as a form (editable grid view).

                        In the meantime I also would need to see the full code you have in the onRecord and on onScriptInit events - can you post them?

                        Plus also confirm the type for the field that will hold the "trash" icon?

                        Thanks

                        Comment


                        • #13
                          Originally posted by adz1111 View Post
                          I'll have a look when I can as a form (editable grid view).

                          In the meantime I also would need to see the full code you have in the onRecord and on onScriptInit events - can you post them?

                          Plus also confirm the type for the field that will hold the "trash" icon?

                          Thanks
                          onScriptInit event
                          Code:
                          $sqlq = "SELECT COUNT(*) FROM treatment_history WHERE treatment_id = [t]";        
                          
                          sc_lookup(my_data, $sqlq);
                          
                          if ({my_data} === false) {
                          	echo "<script type='text/javascript'>alert('DB Access error. Message = " . 
                          		{my_data_erro} . "');</script>";
                          	[last_record] = 0;
                          
                          } else {
                          	[last_record] = {my_data[0][0]};
                          }
                          
                          [rec_pos] = 0;
                          OnLoadRecord event
                          Code:
                          [rec_pos] += 1;
                          
                          if ( [rec_pos] == [last_record] ) {		// if last record only
                          	{delete} = "<img src='../_lib/img/delete_16.png' alt='Delete' title='Delete' >";   
                          } else {
                          	{delete} = '';
                          }
                          {delete} field type:HTML image

                          Regards

                          Comment


                          • #14
                            walid

                            Also - why have the detail as editable view? Your picture does not show the whole row. If you are looking to NOT allow deletion except on the last row (and presumably disallow editing too on only the last row), then using editable view provides you with way more features than you need - meaning you have to unpick it all. Why not use just a plain grid as your detail, and then set it as per my post?

                            EDIT: Re the issue with the HTML text displaying and not the image - that is a known bug right now with HTML Image field types in forms - they work correctly in Grids now though.
                            Last edited by adz1111; 04-28-2015, 08:30 AM.

                            Comment


                            • #15
                              Thank you for looking at this.
                              i will do it like your advice


                              regards

                              Comment

                              Working...
                              X