Hi all,
With some guidance from Selwyn (thanks Selwyn) and some code I was able to update my grid Group Header totals while updating a record in a child link grid that affected those group summary totals.
Here is what I did:
- Wrap the groupSummary.FieldNameCount fields with an id= tag to identify those fields later on.
- I have a javascript function jsRefreshStudentGrid() that will handle the refresh of the parent grid, in this method I added an ajaxCallback to call an Xbasic function to calculate the totals.
- In my Xbasic function xbRecalculateGroupHeaderCounters() I then run an SQL statement to grab the totals and then return an e.rtc.A_AjaxResponses to update my Element IDs using document.GetElementById
- I call the jsRefreshStudentGrid() function from the grid afterDetailViewSubmit() and afterDetailViewDeleteRecord() events.
Here are the functions:
Code:
//Refresh the StudentGrid and update its Group Header totals //This function will call an ajaxCallback to calculate the Group Header totals. function jsRefreshStudentGrid() { // Get the parent object which is the StudentsGrid and if // exist, refresh it. var pObj = {grid.Object}.getParentObject(); if (typeof pObj=="object") { //Get the row for the parent var prowNum = pObj._selectedRow; //Refresh the current row for the parent pObj.refreshRow(prowNum); // Get all the values for the Search part fields and call an Ajax CallBack // to calculate the Total IEP hours and minutes. var vStudentIsInactive = pObj.getValue('S','STUDENTISINACTIVE'); //Getting value of 'range' fields in the Search part. You can't use .getValue(). You have to use low level Javascript. //so lets get the ParentGridAlias name so we can reference the date range field correctly. //Sample: var val1 = $('{grid.componentname}.S.STARTDATE').value; var pAlias = {Grid.object}.parentGridAlias; var vDateOfBirthStart = $(pAlias + '.S.DATEOFBIRTH').value; var vDateOfBirthEnd = $(pAlias + '.S._TO.DATEOFBIRTH').value; //Get other search field values var vHomeDistrict = pObj.getValue('S','HOMEDISTRICT'); var vFirstName = pObj.getValue('S','FIRSTNAME'); var vLastName = pObj.getValue('S','LASTNAME'); var vProvider1FullName = pObj.getValue('S','PROVIDER1FULLNAME'); var vProvider2FullName = pObj.getValue('S','PROVIDER2FULLNAME'); var vSiteName = pObj.getValue('S','SITENAME'); var vNYCIDNumber = pObj.getValue('S','NYCIDNUMBER'); //Prepare the ajaxCallback addional data pair values from the search part field values var vAdditionalData = 'vStudentIsInactive=' + vStudentIsInactive + '&vDateOfBirthStart=' + vDateOfBirthStart + '&vDateOfBirthEnd=' + vDateOfBirthEnd vAdditionalData = vAdditionalData + '&vHomeDistrict=' + vHomeDistrict vAdditionalData = vAdditionalData + '&vFirstName=' + vFirstName + '&vLastName=' + vLastName vAdditionalData = vAdditionalData + '&vProvider1FullName=' + vProvider1FullName + '&vProvider2FullName=' + vProvider2FullName vAdditionalData = vAdditionalData + '&vSiteName=' + vSiteName + '&vNYCIDNumber=' + vNYCIDNumber //Call the Xbasic xbRecalculateGroupHeaderCounters with an ajaxCallback {grid.Object}.ajaxCallback('D','1','xbRecalculateGroupHeaderCounters','', vAdditionalData); } }
Code:
'-- This function is called from the js function jsRefreshStudentGrid ' It will expect all values used in the search part to calculate the ' Total IEP Hours and Minutes counter used in the Group Header of the StudentGrid function xbRecalculateGroupHeaderCounters as c (e as p) dim cn as sql::Connection dim args as sql::Arguments dim rs as SQL::ResultSet dim vSelect as c '-- Process Arguments passed from the jsRefreshStudentGrid function data pair values if e.vStudentIsInactive = "" then args.add("StudentIsInactive", 0) else args.add("StudentIsInactive", convert_type(e.vStudentIsInactive,"N")) end if args.add("HomeDistrict", convert_type(e.vHomeDistrict,"N")) '-- If dates are blank, then set them to 1/1/1800 if e.vDateOfBirthStart = "" .or. e.vDateOfBirthEnd = "" then args.add("DateOfBirthStart", convert_type("1/1/1800","D")) args.add("DateOfBirthEnd", convert_type("1/1/1800","D")) else args.add("DateOfBirthStart", convert_type(e.vDateOfBirthStart,"D")) args.add("DateOfBirthEnd", convert_type(e.vDateOfBirthEnd,"D")) end if args.add("FirstName", e.vFirstName) args.add("LastName", e.vLastName) args.add("Provider1FullName", e.vProvider1FullName) args.add("Provider2FullName", e.vProvider2FullName) args.add("SiteName", e.vSiteName) args.add("NYCIDNumber", e.vNYCIDNumber) '-- Create SQL to calculate the group totals using the current values ' in the Search Part. vSelect =<<%txt% SELECT COALESCE(SUM(v.FrequencyHours), 0) AS FrequencyHours, COALESCE(SUM(v.FrequencyMinutes), 0) AS FrequencyMinutes FROM Students s LEFT OUTER JOIN Providers p ON s.FK_Providers = p.PK_Providers LEFT OUTER JOIN Providers p2 ON s.FK_Providers2 = p2.PK_Providers LEFT OUTER JOIN ClassSites cs ON s.FK_ClassSites = cs.PK_ClassSites LEFT OUTER JOIN vIEP_Frequency v ON s.PK_Students = v.FK_Students WHERE (s.StudentIsInactive = :StudentIsInactive OR :StudentIsInactive IS NULL) AND ((s.DateOfBirth >= :DateOfBirthStart AND s.DateOfBirth <= :DateOfBirthEnd) OR :DateOfBirthStart = '1/1/1800') AND (s.HomeDistrict = :HomeDistrict OR :HomeDistrict = 0) AND (s.FirstName = :FirstName OR :FirstName = '') AND (s.LastName = :LastName OR :LastName = '') AND (p.cfpFullName = :Provider1FullName OR :Provider1FullName = '') AND (p2.cfpFullName = :Provider2FullName OR :Provider2FullName = '') AND (cs.SiteName = :SiteName OR :SiteName = '') AND (s.NYCIDNumber = :NYCIDNumber OR :NYCIDNumber = '') %txt% '-- Open the connection and calculate the group totals if cn.open("::name::BCI") then if cn.execute(vSelect,args) = .t. rs = cn.ResultSet if eval_valid("rs.data(1)") then dim currentIEPHoursCount as n = rs.data("FrequencyHours") dim currentIEPMinutesCount as n = rs.data("FrequencyMinutes") dim myjs as c =<<%js% document.getElementById('IEPHoursCount').innerHTML = {currentIEPHoursCount} ; document.getElementById('IEPMinutesCount').innerHTML = {currentIEPMinutesCount} ; %js% '-- Update the Group Header totals using the getElementByID IN myjs aa = e.rtc.A_AjaxResponses aa[].text = evaluate_string(myjs) aa[..].id = 100 'the order in which AjaxResponses are sent to the browser end if end if cn.close() end if end function
Leave a comment: