简体   繁体   中英

Kendo UI Grid: How to change cell text based on a bit value

I have a Kendo Grid which displays some records and users have the ability to edit the records. If a record is set to IsReadOnly then that row controls are disabled meaning users can only read it but no edits. Below are different columns of grid.

  columns: [
                { field: "Id", hidden: true },
                { field: "DisplayValue", title: "Description" },
                { field: "DisplayOrder", hidden: true },
                { field: "IsActive", hidden: true },
                { field: "IsReadOnly", title: "Read Only"},
                { template: kendo.template($("#activate-command-template").html()), width: 93 }
            ]

If IsReadOnly comes true when I want to display a message for that records saying "Contact IT to make this row editable" and if its false then I would display an empty string. How Do I achieve this in dataBound event ? Below is my dataBound event:

if (adminView.viewModel.get("selectedControllerItemName") == "IntakeReferralMethod") {
                        var gridData = grid.dataSource.view();
                        for (var i = 0; i < gridData.length; i++) {
                            var currentUid = gridData[i].uid;
                            if (gridData[i].IsReadOnly == true) {
                                var currenRow = grid.table.find("tr[data-uid='" + currentUid + "']");
                                var activateButton = $(currenRow).find(".k-button").attr("disabled", true);
}

My problem: How do I set the text for the records to "Contact IT" if IsReadOnly is true and set the text to empty string when IsReadOnly is false?

Please let me know if some clarification is needed. I been searching for hours and cannot find anything which can help me understand how to manipulate text on grid when certain bit field is true or false.

In each field where you want the "Contact IT" text to appear, you can add a template. Kind of like what you have in the last field, but you can bind the template to the data in the row and put a condition that checks the data and displays one string or the other. It sounds more complicated than it is. I'm not in front of a computer but from memory here goes an example:

{ //field info... template: '#: isReadOnly ? "Contact IT" : "" ' }

The #: is what binds the template to the current row's data. The question mark and colon form an inline if-then-else statement. isReadOnly is one of the fields in your row.

Give it a try and post back with the results

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM