jQuery UI Widgets Forums Grid How to hide column without datafield?

Tagged: ,

This topic contains 2 replies, has 2 voices, and was last updated by  korell 9 years, 5 months ago.

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author

  • korell
    Participant

    Hello,

    How can I hide a column that does not have an associated datafield?
    I have a column in my grid that contains an image button to delete that row. I have created the column like this:

    { text: 'Delete', width: 50, cellsalign: 'center', menu: false, cellsrenderer: deleteApplicationButton }

    and the cellsrenderer like this:

          var deleteApplicationButton = function (row) {
                var html = "<form action='PreKApplications/DeleteConfirmed' method='post'><input name='__RequestVerificationToken' type='hidden' value=" + securityToken + " /><div id='DeleteApplicationSpan' onclick=deleteApplication(this," + $("#applicationsTable").jqxGrid('getCellValue', row, 'ID') + ") title='Click to delete application' style='background: url(@Url.Content("~/Content/Images/delete-icon.png")) no-repeat center right; width: 22px; height: 22px; display: block; cursor:pointer;margin:0 auto;' ></div><input type='hidden' name='ID' value='" + $("#applicationsTable").jqxGrid('getCellValue', row, 'ID') + "' /></form>";
                return html;
            }

    I only want this column to be visible by administrators like this:

            $('#applicationsTable').on('bindingcomplete', function (event) {
                if (isAdministrator == "True") {
                    $("#applicationsTable").jqxGrid('showcolumn', 'Delete');
                } else {
                    $("#applicationsTable").jqxGrid('hidecolumn', 'Delete');
                }
            });

    However, this doesn’t work since this column does not have a datafield.

    So, how can I hide this column for administrators?

    Thanks,
    Sacha


    Peter Stoev
    Keymaster

    Hi Sacha,

    There are no columns without datafields in jqxGrid. Each column should have datafield and it should be unique string.

    Best Regards,
    Peter Stoev

    jQWidgets Team
    http://www.jqwidgets.com/


    korell
    Participant

    Hi Peter,

    Thanks for the quick response.

    The above code works fine, even without datafield. In your example of a button column (http://www.jqwidgets.com/custom-grid-cells-rendering/) you use the record’s “id” field as the datafield, however in my case, I need to display the record ids in a separate column. Does that mean I have to create a field in my database table that I wouldn’t use otherwise just to bind to a button column to be able to reference it? What if I need multiple button columns? Wouldn’t it be much better to have a column_id property that can be set at design time to reference jqxGrid columns instead of datafield?

    Can you suggest a solution? I need to have a button column with at least a “Delete” button that I need to be able to hide from all users except administrators.

    Thanks,
    Sacha

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.