How can we protect some parts of a sheet using rubyXL? - ruby

I'd like the user of my xlsx spreadsheet to edit some parts of a sheet but not the most of it. Or in other words, I'd like only some parts of the sheet to be protected.
I learned how to protect the sheet using rubyXL with the code below:
sheetProtection = RubyXL::WorksheetProtection.new(
password: hashedPass,
sheet: true,
objects: true,
scenarios: true,
format_cells: true,
format_columns: true,
insert_columns: true,
delete_columns: true,
insert_rows: true,
delete_rows: true
);
wsData = workbook['data'];
wsData.sheet_protection = sheetProtection;
Say, I'd like the user to only edit the cell range C2:C13 of the said sheet.
I can't find the syntax on how to do that from the documentation of the rubyXL nor how to use that documentation (please forgive my ignorance). I'm at a loss when I click any link on the side of that page, because for me, it seems the only friendly one is the main page. Google is not helping. In the above code, I don't know how they get the sheet_protection property of the worksheet as available for use.
In the closest clue I found, I learned that "unprotection" of a cell can be achieved by a cell style. So I tried creating a style and putting that one in a cell, but that one too proved to be difficult due to lack of guides.
In the cell_style.rb of the github repo, I found something about Protection and CellStyle classes.
unprotected = RubyXL::Protection.new(
locked: false,
hidden: false
);
unprotecStyle = RubyXL::CellStyle.new(
name: 'unprotected style'
);
I can't find in the docs how to put them together, or even apply a style on a cell:
wsData[1][2].cell_style = unprotecStyle;
# undefined method `cell_style=' for #<RubyXL::Cell(1,2): "cell-content", datatype="str", style_index=8>
I'm not even sure if I'm on the right track. Please help.

Perhaps you figured this out already, but this worked for me...
Given a worksheet and a cell, I did:
worksheet.
workbook.
cell_xfs[cell.style_index || 0].
protection = RubyXL::Protection.new(
locked: false,
hidden: false
)
Then I did:
worksheet.sheet_protection = RubyXL::WorksheetProtection.new(
sheet: true,
objects: true,
scenarios: true,
format_cells: true,
format_columns: true,
insert_columns: true,
delete_columns: true,
insert_rows: true,
delete_rows: true
)
Which protected the entire worksheet except for the cell.

Related

Problem getting edited cell value using cell editing events in jqGrid

I've just started using jqGrid and am having a problem trying to get the value of an edited cell when it loses focus. I have a two-column grid with only the first column editable. Eventually my aim is that when the user clicks out of a cell in this column, it will make an Ajax call to the server to populate the second column with a value. Right now, I'm testing by just having the value of the cell displayed in a div on the page. I find the event model very unclear and have tried all the events related to cell editing (beforeEditCell, afterEditCell, beforeSubmitCell, onSubmitCell, etc.) Only the beforeSubmitCell and onSubmitCell events actually return the value. The problem in my test is that when I first edit a cell, the correct value is shown, but when I edit other cells it keeps showing the value and row ID from the first edited cell. Here is my test page: http://www.galcott.com/jqgrid.html where you can see this happening and look at the code.
You have a lot of errors in your code and setup, which causes unexpected behavior.
1.You do not have included one of the important file - the language file. If you have include it you will see where is the problem.
2.You do not have include css framework file, which will cause sometime unexpected behavior.
3.You save a error in the grid parameter cellsubmit - in your code it is cellSubmit, while the working option is cellsubmit - JavaScript is case sensitive
4.At last the event onSubmitCell as I say in my comment should return true or false i.e
onSubmitCell: function(rowid, cellname, value, iRow, iCol) {
$('#celldata').html(iRow + ' ' + value);
if(some condition) {
return false;
}
return true;
}
In your code do:
$("#tbl1").jqGrid({
width: 400,
height: 400,
cellsubmit: 'clientArray',
editurl: 'clientArray',
...
and it will work

How to change the state of a CheckBox from true to false when I click in a different Check box

I am using Visual Studio in VB, I have 3 check boxes, one is set by default to be True, but when I select on of the other checkbox and change it to True, I want to set all the other Checkboxes to False I have tried some fairly simple code but it doesn't work - can someone help me? I am newish to code...!
I have tried
If CheckBox1.Checked = True Then
ChecBox2.checked= False
CheckBox3.checked = False
End If

grayt_autoStartup = true,

According to http://www.webspellchecker.net/samples/grayt-ckeditor-plugin.html
the statement CKEDITOR.config.grayt_autoStartup = true; should activate "GrammarAsYouType (GRAYT) for CKEditor 4+" grammer service on the editor
Their demo code did not even show the spelling button on my local test.
The code from http://sdk.ckeditor.com/samples/spellchecker.html did show the spelling options but not grammer.
Tried to add to the config:"grayt_autoStartup = true," like the "scayt_autoStartup: true," works, but then the entire UI was gone and no spell or grammar check.
Any one has a spelling AND grammar working in a local deployment?
Thanks in advance
You are right - GRAYT for CKEditor can be started like this:
grayt_autoStartup: true
For adding spelling button to CKEditor UI you need the following:
CKEDITOR.config.toolbar = [{
name: 'editing',
items: ['Scayt']
}];
There is no separate button for GRAYT. So you will have button only for SCAYT.
jsfiddle: https://jsfiddle.net/jalners/j4ytgb2v/

jqGrid loses edits when you reorder or filter

I have a jqGrid that has the following properties;
grid.jqGrid({
datatype: "local",
data: GRID.GridData,
colModel: GRID.availableGridColumns['columnModel'],
loadonce: true,
It loads the data just fine.
I then make an inline edit to one to the cells.
I then apply a filter, or a sort, and the edit I made to the cell is now gone and the value is back to its original value.
I also have this;
var rowData = $('#Grid').jqGrid('getRowData', "11332601");
rodData.State = "Open";
$('#Grid').setRowData("11332601", rowData)
The value in the cell is changed but when I apply a filter or a sort, the cell value is changed back to its original value.
This can also be demonstrated here http://www.trirand.com/blog/jqgrid/jqgrid.html and then opening "New in version 3.3" and selecting the "Cell Editing" link.
Sort the grid by "Amount", change the value of "50.00" to be say "51.00". Sort by amount again and then again and you will see that "51.00" has changed back to "50.00".
Is there a workaround for this behavior?

How to improve performance of jqGrid

I have more than 1000 rows to populate data through jqGrid. When I populate data through jqGrid, jqGrid takes more than 20 seconds to populate data. This time is taken only by jqGird (query execution time and other time is excluded). I have a requirement to populate 1000 rows by using jqGrid and I don't want to use Pagination. Please help me how to increase the performance of jgGrid.
The versions we are using are:
jgGrid: 3.6.4
jQuery:1.4.2
jQuery UI:1.7.2
Browser: IE 7
Following is the code:
jQuery("#displayItemPerformanceGrid").jqGrid({
//datatype: displayItemPerformanceGridData, //json
url:'/DISMGMT/StandardProxy/displayItemPerformanceService?userRole='+userRole+
'&userName='+userName+'&duration='+displayDuration+'&userId='+userId,
datatype: 'json',
colNames: ["CM","Display Location","Display Name","Item","Item Description",
"Store","DC","Date","Type","Promo Retail","Reg. Retail 50" "Units",
"Sales $", "Profit $"],
// $("#load_navGrid").html("Loading...").show();
colModel: [
{name:"cmName",index:"cmName",classes:"metric",width:130,resizable:true,
align:"left"},
{name:"displayLocation",index:"displayLocation",width:80,align: "left"},
{name:"displayName",index:"displayName",width:225,align:"left"},
{name:"item",index:"item",sorttype:"int",width:60,align:"left"},
{name:"itemDescription",index:"itemDescription",width:230,align:"left"},
{name:"store",index:"store",sorttype:"int",width: 70,align: "right"//,
//unformat : spaceFormatter
},
{name: "dc", index: "dc", sorttype: "int",width: 60,align: "right"//,
//unformat : spaceFormatter
},
{name:"date",index:"date",sorttype:"date",datefmt:"mm-dd-yy",width:80,
align: "left"},
{name: "type",index: "type",width: 45,align: "left"},
{name: "price",index: "price",width: 70,align: "left"},
{name: "regRetail",index: "regRetail",width: 70,align: "left"},
{name:"units",index:"units",sorttype:"int",width:45,align:"right",
unformat : spaceFormatter},
{name:"sales",index:"sales",sorttype:"int",width:45,align:"right",
unformat : spaceFormatter},
{name:"profit1",index:"profit1",sorttype:"int",width:40,align:"right",
unformat : spaceFormatter}
],
width: 982,
height: 137,
toolbar: [true, "top"],
viewrecords: true,
rowNum: 1500,
// gridview:true,
loadonce:true
});
Please suggest me how to improve performance of jqGrid
Use virtual scrolling (look at the demo, New in version 3.7 -> Virtual scrolling).
You question look like another question from trirand forum which I recently answered. To be sure I can repeate the information here.
In general for jqGrid is not a problem to display 1000 rows. The demo example which has 15 columns and 1000 rows will be displayed on my computer quickly enough. I have no IE7, but in IE8, IE9 beta, Chrome, Firefox, Opera and Safari (all in the last versions) the time to display the table is very quickly. In the example I use the modified jQuery UI, where .ui-widget :active { outline: none; } is removed. See here and here for more detailes.
So to be able to help you one need have possible full definition of your jqGrid inclusive the HTML code and test JSON data. You can capture the data with respect of Fiddler or Firebug. Probably you has some datatypes, don't use gridview:true option and use afterInsertRow method which make jqGrid working slower espetially for lagre pages. It can be also that you do many work inside of gridComplete or loadComplete event handler. So without having the code I can only guess. It can be also important which column you use for the sorting of the data and how you inserts the data in the grid (with data parameter, loadonce:true or using addRowData).
Another point of view is the usage of local paging. If you prefer to return all 1000 rows at once from the server it disturbs you not to use local paging of the 1000 rows of data. On the next example I demonstrate this. The problem is easy: all 1000 rows can not be displayed for the user at once. The user have to scroll the rows either in web browser or with respect fo jqGrid local paging. The advantage of the local paging is: only the data for one page will be placed in the table. All other data will be only hold in the sorted form internally. It can improve the performance and don't change almost anything from the users point of view.
More then that, having intelligent local filtering of data with respect of toolbar filtering or single field/advanced searching can help the user very much to analyse a lot of information from the 1000 rows which will be displayed him. Local filtering and local paging can be used very native together.

Resources