{"id":2109,"date":"2020-02-09T11:11:26","date_gmt":"2020-02-09T16:11:26","guid":{"rendered":"https:\/\/xlinesoft.com\/blog\/?p=2109"},"modified":"2020-02-13T15:28:52","modified_gmt":"2020-02-13T20:28:52","slug":"making-new-record-visible-on-the-list-page","status":"publish","type":"post","link":"https:\/\/xlinesoft.com\/blog\/2020\/02\/09\/making-new-record-visible-on-the-list-page\/","title":{"rendered":"Making new record visible on the List page"},"content":{"rendered":"<p>When we added a new record and returned back to the List page that new record may not be clearly visible on the page. Depending on what page we on, what sort or is applied, how many records are on the page &#8211; we may simply be on the wrong page. This can be useful when, for instance, you are transferring a large amount of data from paper to the database and this kind of visual indication can be helpful to keep track of the process. <\/p>\n<p>In this article, we will show you a technique that does the following. After the new record is added we find out which page it belongs to, redirect the user to that page, highlight the record and also scroll the page if the record is below the fold. <\/p>\n<p><a href=\"https:\/\/xlinesoft.com\/blog\/wp-content\/uploads\/2020\/02\/scr.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/xlinesoft.com\/blog\/wp-content\/uploads\/2020\/02\/scr-300x201.png\" alt=\"\" width=\"300\" height=\"201\" class=\"alignnone size-medium wp-image-2113\" srcset=\"https:\/\/xlinesoft.com\/blog\/wp-content\/uploads\/2020\/02\/scr-300x201.png 300w, https:\/\/xlinesoft.com\/blog\/wp-content\/uploads\/2020\/02\/scr.png 733w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><br \/>\n<!--more--><\/p>\n<p>Things to change in the code:<br \/>\n&#8211; <strong>products<\/strong> &#8211; the name of the table, we need it for the redirect<br \/>\n&#8211; <strong>ProductID<\/strong> &#8211; the name of the key column<\/p>\n<h4>1. Add page: AfterAdd event:<\/h4>\n<p>Saving new record ID in the session variable. Execute previously saved SQL query, loop through the recordset finding our new record. Redirect to the corresponding page.<\/p>\n<p><strong>PHP code:<\/strong><\/p>\n<pre name=\"code\" class=\"php:nocontrols\">\r\n$_SESSION[\"ProductID\"]=$keys[\"ProductID\"];\r\n\r\n$i=0;\r\n$rs = DB::Query($_SESSION[\"ProductsSQL\"]);\r\n \r\nwhile( $data = $rs->fetchAssoc() )\r\n{\r\n$i++;\r\nif ($data[\"ProductID\"]==$keys[\"ProductID\"])\r\n\tbreak;\r\n}\r\n\r\n$page = floor($i \/ $_SESSION[\"pageSize\"] )+1;\r\n\r\nheader(\"Location: products_list.php?goto=\".$page);\r\nexit();\r\n<\/pre>\n<p><strong>C# code:<\/strong><\/p>\n<pre name=\"code\" class=\"csharp:nocontrols\">\r\ndynamic i = null, page = null;\r\nXSession.Session[\"ProductID\"] = keys[\"ProductID\"];\r\ni = new XVar(0);\r\nrs = XVar.Clone(DB.Query((XVar)(XSession.Session[\"ProductsSQL\"])));\r\nwhile(XVar.Pack(data = XVar.Clone(rs.fetchAssoc())))\r\n{\r\n\ti++;\r\n\tif(data[\"ProductID\"] == keys[\"ProductID\"])\r\n\t{\r\n\t\tbreak;\r\n\t}\r\n}\r\npage = XVar.Clone((XVar)Math.Floor((double)(i \/ XSession.Session[\"pageSize\"])) + 1);\r\nMVCFunctions.HeaderRedirect((XVar)(MVCFunctions.Concat(\"products_list.php?goto=\", page)));\r\nMVCFunctions.ob_flush();\r\nHttpContext.Current.Response.End();\r\nthrow new RunnerInlineOutputException();\r\n<\/pre>\n<h4>2. List page: BeforeSQLQuery event<\/h4>\n<p>Saving the current SQL query and page size in session variables<\/p>\n<p><strong>PHP code:<\/strong><\/p>\n<pre name=\"code\" class=\"php:nocontrols\">\r\n$_SESSION[\"ProductsSQL\"] = $strSQL;\r\n$_SESSION[\"pageSize\"] = $pageObject->pageSize;\r\n<\/pre>\n<p><strong>C# code:<\/strong><\/p>\n<pre name=\"code\" class=\"csharp:nocontrols\">\r\nXSession.Session[\"ProductsSQL\"] = strSQL;\r\nXSession.Session[\"pageSize\"] = pageObject.pageSize;\r\n<\/pre>\n<h4>3. List page: AferRecordProcessed event<\/h4>\n<p>Changing the background color of the new record. <\/p>\n<p><strong>PHP code:<\/strong><\/p>\n<pre name=\"code\" class=\"php:nocontrols\">\r\nif ($data[\"ProductID\"] == $_SESSION[\"ProductID\"] )  \r\n$record[\"css\"]=\"background:yellow;\";\r\n<\/pre>\n<p><strong>C# code:<\/strong><\/p>\n<pre name=\"code\" class=\"csharp:nocontrols\">\r\nif(data[\"ProductID\"] == XSession.Session[\"ProductID\"])\r\n{\r\n\trecord.InitAndSetArrayItem(\"background:yellow;\", \"css\");\r\n}\r\n<\/pre>\n<h4>4. List page: BeforeDisplay event<\/h4>\n<p>Bullets 4 and 5 are only required if you display a lot of records on the list page and need to scroll the page so the new record is visible. This code most likely is not required if you only display twenty records per page. <\/p>\n<p><strong>PHP code:<\/strong><\/p>\n<pre name=\"code\" class=\"php:nocontrols\">\r\n$pageObject->setProxyValue(\"ProductID\", $_SESSION[\"ProductID\"]);\r\n<\/pre>\n<p><strong>C# code:<\/strong><\/p>\n<pre name=\"code\" class=\"csharp:nocontrols\">\r\npageObject.setProxyValue(new XVar(\"ProductID\"), (XVar)(XSession.Session[\"ProductID\"]));\r\n<\/pre>\n<h4>5. List page: Javascript OnLoad event<\/h4>\n<pre name=\"code\" class=\"javascript:nocontrols\">\r\nvar allRecords = pageObj.getAllRecords();\r\nallRecords.forEach(function(row){\r\nif( row.getFieldText('ProductID')==proxy['ProductID']) {\r\n$([document.documentElement, document.body]).animate({\r\n        scrollTop: row.fieldCell('ProductID').offset().top\r\n    }, 2000);\r\n}\r\n})\r\n<\/pre>\n<p>Enjoy!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>When we added a new record and returned back to the List page that new record may not be clearly visible on the page. Depending on what page we on, what sort or is applied, how many records are on the page &#8211; we may simply be on the wrong page. This can be useful when, for instance, you are transferring a large amount of data from paper to the database and this kind of visual indication can be helpful to keep track of the&#8230;<span class=\"clearfix clearfix-post\"><\/span><a href=\"https:\/\/xlinesoft.com\/blog\/2020\/02\/09\/making-new-record-visible-on-the-list-page\/\" class=\"more-link\">Continue Reading <span class=\"screen-reader-text\">&#8220;Making new record visible on the List page&#8221;<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16,1,8],"tags":[],"_links":{"self":[{"href":"https:\/\/xlinesoft.com\/blog\/wp-json\/wp\/v2\/posts\/2109"}],"collection":[{"href":"https:\/\/xlinesoft.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/xlinesoft.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/xlinesoft.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/xlinesoft.com\/blog\/wp-json\/wp\/v2\/comments?post=2109"}],"version-history":[{"count":12,"href":"https:\/\/xlinesoft.com\/blog\/wp-json\/wp\/v2\/posts\/2109\/revisions"}],"predecessor-version":[{"id":2129,"href":"https:\/\/xlinesoft.com\/blog\/wp-json\/wp\/v2\/posts\/2109\/revisions\/2129"}],"wp:attachment":[{"href":"https:\/\/xlinesoft.com\/blog\/wp-json\/wp\/v2\/media?parent=2109"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/xlinesoft.com\/blog\/wp-json\/wp\/v2\/categories?post=2109"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/xlinesoft.com\/blog\/wp-json\/wp\/v2\/tags?post=2109"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}