can somebody please help me with making readonly rows in Quick edit view in sharepoint 2013. There are readonly column using AllowgridEditing = false but there seems to be no possible way to make readonly rows. (edit: Iam trying to achieve it using javascript. So when list is loaded certain rows to be made readonly based on some values in a particular cell of that row)
2 Answers
You can set few fields as read-only in a Quick edit / Datasheet mode of a List view through Sharepoint designer.
- Create a List view with all the required fields (Including Read only and editable fields) and by applying required filters
- Now, open the List in sharepoint designer and edit the Newly created list view file in 'Advanced Mode'. You can do it be right clicking on the View Name in the List
- In the file, go to 'XMLdefinition' tag, inside that you can see 'ViewFields' section where all the fields added in step 1 are available.
- For all the read only fields, you add ReadOnly="TRUE" attribute in the corresponding FieldRef tag.
- So, a Field ref tag for a read only field would be as
<FieldRef Name="Product" ReadOnly="TRUE"/>
- Now save the file and open it in browser.
- Once you go to Quick Edit, you can see the read only columns are disabled.
-
Thanks @chinna for prompt reply and i am so sorry for not being clear first time. i have edited it. i would've wanted to achieve this using js and make Cells readonly if the row contain any value. for eg. in your snap, if WorkRequest = "Sample Request" then make "New Component Item 0" and "150" readonly.– ManojCommented Sep 16, 2017 at 3:46
I have managed to make cells readonly. I am disabling keys to prevent editing. here is the script :
(It is just a workaround for now but if you have any other answers Please let me know. Thanks)
$(document).on("keydown", ".ms-listviewtable", function (m) {
var currentUser = $(".ms-listviewtable.ms-listviewgrid").find(".ms-jsgrid-cell-selected-editable").parent().find("td").eq(7).text().trim();
if(currentUser == "Piping"){
m.preventDefault();
alert("editing not allowed");
}
});
$(document).on("mouseup", "#jsgrid_combobox", function (e) {
var editable = $(".ms-jsgrid-cell-selected-editable");
if (editable.parent().find("td").eq(7).text() == "Piping") {
$(document).on("click", "#jsgrid_combobox input,.combobox-dropdown", function (e) {
$e.preventdefault();
});
$(document).on("keyup", "#jsgrid_combobox input", function (e) {
$e.preventdefault();
});
$(this).find("input").prop("disabled", true);
alert("You can not edit");
} else {
$(document).on("click", "#jsgrid_combobox input", function (e) {
$(this).unbind("click");
});
$(document).on("keyup", "#jsgrid_combobox input", function (e) {
$(this).unbind("keyup").keyup();
});
$(this).find("input").prop("disabled", false);
}
})