iSeller Commerce
iSeller POS Retail
iSeller POS F&B
iSeller POS Express
Crosslight
WebUI
ClientUI
What's New
Download Trial
Web Solution
Mobile Solution
Enterprise Solution
Custom Development
Blog
Community
Latest Development Blogs
ForumPostTopic
Browse By Tag
I have the following client script that will expand or collapes a preview row when the users clicks anywhere on the row without requring the user to click the arrow. Grid has the CellClickAction to RowSelect.
The code works except if the user happens to click on the arrow to expand/collapse the row, if the row is already expanded it will collapse it and then expand it, if it is collapsed it will open and then collaps it.
function WebGrid1_OnRowSelect(controlId, tblName, rowIndex, rowEl) { var WebGrid1 = ISGetObject(controlId); var row = WebGrid1.GetSelectedObject().GetRowObject(); if (row.Type == 'Record') { if (row.PreviewRowExpanded) { row.CollapsePreviewRow(); } else { row.ExpandPreviewRow(); }; }; WebGrid1.SetStatus1("", "Ready.", "CommonText/Ready") return true; }
Any suggestions?
Thanks
Hi John,
For this matter, you can check if the preview button already being clicked or not and handle the row by using this code:
var buttonClick = false; function WebGrid1_OnRowSelect(controlId, tblName, rowIndex, rowEl) { var WebGrid1 = ISGetObject(controlId); if (buttonClick == false) { var row = WebGrid1.GetSelectedObject().GetRowObject(); if (row.Type == 'Record') { if (row.PreviewRowExpanded) row.CollapsePreviewRow(); else row.ExpandPreviewRow(); } } buttonClick = false; WebGrid1.SetStatus1("", "Ready.", "CommonText/Ready"); return true; } function WebGrid1_OnCellClick(controlId, tblName, rowIndex, cellIndex, cellEl) { var WebGrid1 = ISGetObject(controlId); var el = event.srcElement; if (el.nameProp == "wg_prexp.gif" || el.nameProp == "wg_prcol.gif") buttonClick = true; return true; }
For your information, preview button is image in WebGrid. Hope this helps.
Regards,
Bernard
Thank you, works perfectly...
Glad, I can help you. If you have any further question please don't hesitate to ask us.
Hi Bernard,
I have a follow up question that may be associated with this. If I happen to either 1) add a new column from the context menu or 2) click on a column header to sort that column only after at least viewing a preview first, it appears that the RowSelect and CellSelect events fire and the above code causes the 1st record to always expand. I also get a JS error on the OnCellClick function listed above on the line If (el.nameProp == ...), with description of Object required.
Sorry for this inconvenience. I forgot to put some validation on my code. Here's the fix:
var buttonClick = false; function WebGrid1_OnRowSelect(controlId, tblName, rowIndex, rowEl) { var WebGrid1 = ISGetObject(controlId); if (buttonClick == false) { var row = WebGrid1.GetSelectedObject().GetRowObject(); if (row.Type == 'Record') { if (row.PreviewRowExpanded) row.CollapsePreviewRow(); else row.ExpandPreviewRow(); } } buttonClick = false; WebGrid1.SetStatus1("", "Ready.", "CommonText/Ready"); return true; } function WebGrid1_OnCellClick(controlId, tblName, rowIndex, cellIndex, cellEl) { var WebGrid1 = ISGetObject(controlId); if (cellIndex == 1) { var el = event.srcElement; if (el != null) { if (el.nameProp == "wg_prexp.gif" || el.nameProp == "wg_prcol.gif") buttonClick = true; } } return true; }
Is this problem still occurs after you modified the code? Look forward to hear any feedback from you so I can help you further.
That helps but still problems exist. The code works until you click on the header row to sort a column. Put an alet(cellIndex) in the ObCellClick event, run the page and click on a column to sort by the column, notice that the OncellClick event doesn't run (this is how it should be), now click on any row to view the preview row, then go back and click on a header to sort and notice that the OnCellClick event runs and the cellIndex = 1, I wouldn't think that this event would fire at this time since you are on a header and not a row. if you look at the rowIndex, when you click on the header the rowIndex is what ever the value was when you clicked on a record row.
Also I've notice that the cellIndex of the wg_prexp.gif and wg_prcol.gif is actually 0.
Thanks for your help
I couldn't replicate this problem in our local end. In my sample the image that represent PreviewRow button is on index 1 in cellIndex. Also PreviewRow have index 0 in cellIndex. Could you explain me more detail the step to reproduce this issue? Is there any Row Header on your WebGrid?
Look forward to hear any feedback from you so I can help you further.
On my system, the preview icon and the area around the icon is colIndex = 0, the preview row if collapsed is cellIndex=0.
If I click to expand the preview row and then click on a header to sort, the header row is now colIndex=1, thus the JS code fails. Here is my layout settings:
<LayoutSettings AllowFilter="Yes" AllowGrouping="Yes" AllowSorting="Yes" PagingMode="VirtualLoad" VirtualLoadMode="Custom" GroupByBoxVisible="False" AllowColumnFreezing="No" AllowColumnMove="Yes" AllowExport="No" AlwaysShowHelpButton="false" AllowSelectColumns="Yes" RowLostFocusAction="NeverUpdate" AutoFilterSuggestion="True" FilterBarVisible="false" HideColumnsWhenGrouped="No" InProgressUIBehavior="ChangeCursorToHourGlass" PagingSize="50" ShowFilterStatus="True" RestoreRowSelection="RootTableOnly" VirtualPageSize="50" PagingExportMode="ExportAllData" AllowMultipleSelection="No" GroupRowInfoFormatDefault="[caption] : [value] ([count])" ColumnFooters="Yes" HeaderClickAction="SortSingle" ShowColumnAction="true" RowHeaders="No" CellClickAction="RowSelect"> <FreezePaneSettings ShowInContextMenu="True" MaxFrozenColumns="3" AbsoluteScrolling="True" /> <TextSettings> <TextItems> <ISWebGrid:WebGridTextItem TextItem="CommonText/Refresh" TextValue="Refreshing RDRs" /> <ISWebGrid:WebGridTextItem TextItem="CommonText/NoData" TextValue="There are no RDRs to display, modify the filters above to view RDRs" /> </TextItems> </TextSettings> <AlternatingRowStyle Font-Names="Verdana" BackColor="#ECE9D8" Font-Size="8pt" HorizontalAlign="Center" /> <RowStyle Font-Names="Verdana" Font-Size="8pt" HorizontalAlign="Center" BackColor="#c9c9c9" /> <FooterStyle Font-Names="Verdana" BorderSettings-Left-Color="White" BorderSettings-Top-Color="White" /> <StatusBarStyle BaseStyle="Normal" Font-Bold="True" Font-Size="9pt"> </StatusBarStyle> <ClientSideEvents OnAfterInitialize="OnAfterInitialize" OnRowSelect="WebGrid1_OnRowSelect" OnUnhandledError="WebGrid1_OnUnhandledError" OnResponse="doLoad" OnCellClick="WebGrid1_OnCellClick" /> </LayoutSettings>
I've found out your problem. Your WebGrid doesn't have RowHeader and allow grouping feature make row header dynamically. However, I've fixed my code and with this code the problem that you mentioned above doesn't happen. Here's the code:
var buttonClick = false; function WebGrid1_OnRowSelect(controlId, tblName, rowIndex, rowEl) { var WebGrid1 = ISGetObject(controlId); if (buttonClick == false) { var row = WebGrid1.GetSelectedObject().GetRowObject(); if (row.Type == 'Record') { if (row.PreviewRowExpanded) row.CollapsePreviewRow(); else row.ExpandPreviewRow(); } } buttonClick = false; WebGrid1.SetStatus1("", "Ready.", "CommonText/Ready"); return true; } function WebGrid1_OnCellClick(controlId, tblName, rowIndex, cellIndex, cellEl) { var WebGrid1 = ISGetObject(controlId); var el = event.srcElement; if (el != null) { if(el.tagName == "IMG") { if (el.nameProp == "wg_prexp.gif" || el.nameProp == "wg_prcol.gif") buttonClick = true; } } return true; }
Hope this helps.
Almost there but errors still occur. Once you expand the preview row, if you click on a column header to sort the table I get an error:
'null' is null or not an object 807200101, line 7 character 123668. the statement it breaks on is v59a81.loaded=true;
Also in Firefox, when you sort a column the 1st row is expanded, clicking on the collapse arrow doesn't collapse the preview row and if you click on the header again, the grid no longer response to anything. No error is shown.
I'm using webgrid .101 (2012 R1).
I've fix the code and the second problem (firefox problem) doesn't happen in my local end. Here's the code:
var buttonClick = false; function WebGrid1_OnRowSelect(controlId, tblName, rowIndex, rowEl) { var WebGrid1 = ISGetObject(controlId); if (buttonClick == false) { var row = WebGrid1.GetSelectedObject().GetRowObject(); if (row.Type == 'Record') { if (row.PreviewRowExpanded) row.CollapsePreviewRow(); else row.ExpandPreviewRow(); } } buttonClick = false; WebGrid1.SetStatus1("", "Ready.", "CommonText/Ready"); return true; } function WebGrid1_OnCellClick(controlId, tblName, rowIndex, cellIndex, cellEl) { var WebGrid1 = ISGetObject(controlId); var el = event.srcElement; if (el != null) { if(el.tagName == "IMG") { if (el.src.indexOf("wg_prexp.gif") != -1 || el.src.indexOf("wg_prcol.gif") != -1) { buttonClick = true; } } } return true; }
For the first issue, I couldn't replicate the issue in our local end. Probably the first problem doesn't happen because there's misconfiguration in my code. Could you give me a simple sample that can reproduce the problem in our local end? To resolve, first problem I need to debug the project here. Sorry for my lack. I will look forward to your feedback so I can assist you further.
Regards,Bernard
Hi Bernard and thanks for all your help, but it still does not work. I've decided to drop this and just change CellClickAction to CellSelect making the user click on the arrows to view preview row.
Again Thanks for all your help...
OK then. I'm sorry for my lack. The issue that appear in your scenario doesn't appear in my sample. Maybe if you need this scenario, I'll propose this matter as feature request. If you have any further question, please don't hesitate to ask me.
or
Choose this if you're already a member of Intersoft Community Forum. You can link your OpenID account to your existing Intersoft Social ID.
Choose this if you don't have an Intersoft account yet. Your authenticated OpenID will be automatically linked to your new Intersoft account.
Enter your Wordpress Blogname