C1GridView Column Header Change Causes Rebind

Originally Posted 11 December 2013, 4:57 am EST

  • Originally Posted 11 December 2013, 4:57 am EST

    Hi

    Has anyone found a way to set a column header based on the contents of the bound recordset without causing the grid to rebind.

    In the example the first load doubles the total because I am setting the column header on the footer rowcreated event.

    Kind Regards
    Jamie
    2013/12/C1GridviewGlyph1.zip
  • Reply

    Jamie,

    Thank you for providing your sample application. I was able to notice the issue which you have reported. To resolve this problem, I would suggest you to set the header text using client side code in the loaded event of the GridView. Since you are getting the header text at server side, you can use a hidden field to store that value and then access its value from client side.

    For example, you will need to modify the RowDataBound event like this:

            protected void C1GridView1_RowDataBound(object sender, C1.Web.Wijmo.Controls.C1GridView.C1GridViewRowEventArgs e)
    {
    if (e.Row.RowType == C1GridViewRowType.DataRow)
    {
    DataRowView rv = (DataRowView)e.Row.DataItem;
    TotalAmount += Convert.ToDecimal(rv["Amount"]);
    ShareDescription = rv["AmountDescription"].ToString(); // Set share description
    HiddenField1.Value = ShareDescription;
    }
    }


    In addition to this, you will need to remove the line of code which you use to set the header text from RowCreated event. Next you can access the hidden field value from client side like this.

            $(document).ready(function () {
    $("#C1GridView1").c1gridview({
    loaded: function () {
    var cols = $("#C1GridView1").c1gridview("columns");
    cols[4].options.headerText = $("#HiddenField1").val();
    $("#C1GridView1").c1gridview("doRefresh");
    }
    });
    });


    I have modified your sample and attached it here. Please take a look and let me know if this helps.

    Regards,
    Sankalp
    2013/12/C1GridviewGlyph_Modified.zip
  • Reply

    Hi Sankalp

    Thank you for the demonstration thats great, however is there a way to force the existing formatting? E.g. That column is right aligned, however setting the title, it becomes centre aligned until you sort?

    Also is there a reason why setting the header column server side doesn't update the header e.g. on the databound event?

    Kind Regards
    Jamie

  • Reply

    Jamie,

    I think this problem should be resolved by using client side code. For example, if you want to set the right align the 4 and 5 column header text, then you can use the following code:

                $(".wijgridth").each(function (e, data) {
    if (e === 3 || e === 4) {
    $(this).find(".wijmo-wijgrid-innercell").css("text-align", "right");
    }
    });


    It works well in my testing. Do let me know if this works fine for you.

    Regards,
    Sankalp
  • Reply

    Hi Sankalp,

    Thank you for the code. I'll apply that here.

    Does that mean that on the server side, Databound event the grid is already drawn/finalised? I thought that only took place further down the event chain.

    Kind Regards
    Jamie
  • Marked as Answer

    Reply

    Jamie,

    When the DataBound event fires, the data binding for the GridView is complete; however it is not rendered completely. Let me know if you still face any issues with the client side code.

    Regards,
    Sankalp
Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels