Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
115
WebDataGrid client side function set_hidden is taking a long time to finish
posted

I have the following scenario:

I am trying to hide column based on user input ,a check box with categories, each category has associated a number of columns, when the user uncheck the category I want to hide all the columns in the grid associated with that category and the reverse process, but the set_hidden function is taking forever.

Here is the code I am using:


var sections = [
{ section: 'Authorization', dataFieldName: 'MemberVerified' },
{ section: 'Authorization', dataFieldName: 'TypeOfServiceDescription' },
{ section: 'Requestor', dataFieldName: 'RequestorReceivedDate' },
{ section: 'Requestor', dataFieldName: 'RequestorReceivedTime' },
{ section: 'Requestor', dataFieldName: 'RequestorNotificationDate' },

{ section: 'Admission', dataFieldName: 'AdmissionDate' },
{ section: 'Admission', dataFieldName: 'PlaceOfServiceDescription' },
{ section: 'Claim', dataFieldName: 'ReviewClaims' },
{ section: 'Claim', dataFieldName: 'AccidentFlag' },
{ section: 'Discharge', dataFieldName: 'RequestedLOS' },
{ section: 'Discharge', dataFieldName: 'GoalLOS' }

];

var grid = $find("<%=wdgadmissionhistory.clientid>");
var gridTbl = grid.Element;
var grid_columns = grid.get_columns();

$("input:checkbox")
.on("change",
function () {
var $this = $(this);
var isChecked = $this.is(":checked");
ToggleColumnVisibility($this.prop("name"), isChecked);
});

function ToggleColumnVisibility(sectionName, show) {
var columns = _.filter(sections, { 'section': sectionName });
_.forEach(columns,
function (column) {
ToggleGridColumn(column.dataFieldName, show);
});
}


function ToggleGridColumn(dataFieldName, show) {
var column = grid_columns.get_columnFromKey(dataFieldName);
if (column !== null)
column.set_hidden(!show);
}

Any clue why the last line of code is taking so long

  • 7315
    Offline posted

    Hello Dieppa,

     

    As per the information provided I have created a sample application of WebDataGrid with a checkbox.On checkbox selection i am hiding the column by using set_hidden property of the grid and I notice it is not taking long time.it is working fine at my end. Please find the attached sample.

    Test this project on your PC; whether or not it works correctly may help indicate the nature of this problem.

    if this sample project is not an accurate demonstration of what you're trying to do, please feel free to modify it and send it back, or send a small sample project of your own if you have one.

     

    In the sample I use the following code , I would like you to see if the alert pops up.  if the grid can’t be found, then the grid variable will be null and the alert will show up.  if it does, then this means that the id of the grid is not WebDataGrid1 and probably has its parent ID prepended to it. 

     

    function HideColumn(sender, e) {

                var chkHide = document.getElementById('chkHide');

                var grid = $find("WebDataGrid1");

     

                if (chkHide.checked) {

                       if (grid == null)

                        alert("grid is null");

                    grid.get_columns().get_column(1).set_hidden(true);

     

                }

                else {

     

                    grid.get_columns().get_column(1).set_hidden(false);

                }

            }    return false;
    }

    If this is the case, we can easily fix this.  We can handle the Initialize ClientEvent of the grid and grab the id from there and use it in the button click event.  See below code snippet and how it changes the code a little.

    <ClientEvents Initialize="WebDataGrid1_Grid_Initialize" />//This goes inside of the grid. 

    var dataGridID;
    function WebDataGrid1_Grid_Initialize(sender, eventArgs)
    {
        dataGridID = sender.get_id();
    }

    Please let me know if I can provide any further assistance.

    WebSite16Hide.zip