make some row editable and other row readonly on dhtmlx grid - dhtmlx

i want to make a row in dhtmlx are read only but i want make the other row are editable with some condition like
id%2=0 are editable.
function doInitGrid(){
mygrid = new dhtmlXGridObject('mygrid_container');
mygrid.selMultiRows = true;
mygrid.setImagePath("codebase/imgs/");
mygrid.setHeader("No, Id, Kd Dep, Kd Prog");
mygrid.setInitWidths("30,50,60,60");
mygrid.setColAlign("left,left,left,left");
mygrid.setColTypes("ro,ro,ro,ro");
mygrid.init();
mygrid.load('test.xml');
}

You can use events to customize the grid's behavior. Something like next
mygrid.attachEvent("onEditCell", function(stage, id, index){
if (id%2) return false; //block edit operations
return true;
});

You can also control what is editable on the backend (the process that generates your test.xml data).
I have a fairly elaborate grid where I have the same need. I accomplished this by first setting up my column types using the setColTypes function. Majority rules, meaning if most of the rows for a column are edtxt, then I set it to edtxt here...
myGrid.setColTypes("link,edtxt,ron,ron,edn,edn,ron[=(c4*c15)+c5],edn,edn,ron[=(c7*c15)+c8],edn,edn,ron[=(c10*c15)+c11],ro,ro,ro");
Then for the columns I want to be of a different type I just assign the type while the xml is being build on the back end. I've removed the server-side code (in this case it was pl/sql that generated this xml)...
<?xml version="1.0" encoding="UTF-8"?>
<rows>
<row id="100">
<cell colspan="2" style="font-weight:bold;" type="ro">Inspections</cell>
<cell type="ro"/>
<cell type="ro"/>
<cell type="ro"/>
<cell type="ro"/>
<cell type="ro"/>
<cell type="ro"/>
<cell type="ro"/>
<cell type="ro"/>
<cell type="ro"/>
<cell type="ro"/>
<cell type="ro"/>
<cell type="ro"/>
<cell type="ro"/>
</row>
<row id="1">
<cell>BLAHBLAH^javascript:gotoRec(1745563)^_self</cell>
<cell id="jon"/>
<cell>0</cell>
<cell>0</cell>
<cell id="cticol1">100</cell>
<cell id="cticol2">200</cell>
<cell/>
<cell id="cticol3">0</cell>
<cell id="cticol4">0</cell>
<cell/>
<cell id="cticol5">1.11</cell>
<cell id="cticol6">2.22</cell>
<cell/>
<cell/>
<cell>10000277932021</cell>
<cell>444.4</cell>
</row>
</rows>
So even though some columns are editable, some are a link, etc..., the entire first row will be readonly because I overrode those colTypes in the xml which takes precedence.
Hope this helps.

You can write ed as setcolTypes to make the column editable.
mygrid.setColTypes("ro,ed,ro,ed");

Related

How to define hidden column in Xrm grid

Is there a way how to include hidden column in xrm grid/view ?
Say I have saved query definition like:
<savedquery>
<savedqueryid>{...}</savedqueryid>
<layoutxml>
<grid name="resultset" jump="name" select="1" icon="1" preview="1">
<row name="result" id="entityid">
<cell name="name" width="200" />
<cell name="statuscode" width="100" />
</row>
</grid>
</layoutxml>
<querytype>0</querytype>
<fetchxml>
<fetch version="1.0" output-format="xml-platform" mapping="logical">
<entity name="entity">
<attribute name="name" />
<attribute name="statuscode" />
</entity>
</fetch>
</fetchxml>
</savedquery>
What I'm after is having the column in grid accessible via client api - as it drives the ribbon logic
var allSelectedRows = gridContext.getGrid().getSelectedRows().forEach((row) => {
// this doesn't work if grid doesn't contain statuscode column
let status = row.data.entity.attributes.get("statuscode");
});
Without actually showing the column in UI.
Technically not possible, unfortunately. As there is no property to set hidden columns, also not advisable to do/read unsupported DOM elements access.
You can use SelectedControlSelectedItemIds to pass as a parameter to custom JavaScript and then you can pull the needed column like statuscode from server to do validation.

How can I make even-width columns?

I am very perplexed with the XUL's 'Box Model' layout.
I want to make a table-like layout of elements.
The layout should consist of one row and three columns.
The columns should have the same width and occupy the whole width of the page.
I will put different elements inside the columns, but the width of the columns should remain the same
and the elements should have their normal sizes, not stretched out.
Say, first column is empty, second contains an image, third contains a button.
How can I achieve that?
I tried boxes and grids, but the columns just seem to assume arbitrary width.
Thank you.
This does not work:
<grid>
<columns flex="1">
<column/>
<column/>
<column/>
</columns>
<rows>
<row>
<spacer flex="1"/>
<image src="MyImage.png"/>
<button id="MyButton" label="MyButton"/>
</row>
</rows>
</grid>
Specify the min and max width of each column and make each cell in the grid an hbox width specific widths and heights. Something like this:
<?xml-stylesheet href="chrome://global/skin/" type="text/css"?>
<window id="yourwindow" xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" xmlns:html="http://www.w3.org/1999/xhtml" xmlns:h="http://www.w3.org/1999/xhtml">
<grid>
<columns flex="1">
<column maxwidth="100" minwidth="100"/>
<column maxwidth="100" minwidth="100"/>
<column maxwidth="100" minwidth="100"/>
</columns>
<rows>
<row>
<hbox maxwidth="100">
xxxx xxxxxxxx xxxx xxxxx xxxxxxxx xxxxxxxx
</hbox>
<hbox maxwidth="100" minwidth="100" maxheight="10">
<button id="MyButton1" label="MyButton1"/>
</hbox>
<hbox maxwidth="100" minwidth="100" maxheight="30">
<button id="MyButton1" label="MyButton2"/>
</hbox>
<hbox maxwidth="100" minwidth="100" maxheight="40">
<button id="MyButton3" label="MyButton3"/>
</hbox>
</row>
</rows>
</grid>
</window>
In Xul, the width and length attributes are always in pixels. You cannot specify a percentage like you can with css. This means you will have to know your page width in advance and specify widths accordingly if you want the columns to be evenly spaced and extend to the page width.
Here's another way. Use this:
<?xml-stylesheet href="chrome://global/skin/" type="text/css"?>
<window id="yourwindow" xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
xmlns:html="http://www.w3.org/1999/xhtml" xmlns:h="http://www.w3.org/1999/xhtml">
<grid>
<columns>
<column flex="1"/>
<column flex="1"/>
<column flex="1"/>
</columns>
<rows>
<row>
<button label="MyButton1"/>
<button label="MyButton2"/>
<button label="MyButton3"/>
</row>
</rows>
</grid>
</window>
to create this:
The buttons/columns will adjust as the window size is changed.
I suggest to use in combo with flex="1" on the column elements
<columns equalsize="always">
<column flex="1">
...
a/p documentation
https://developer.mozilla.org/en-US/docs/Mozilla/Tech/XUL/Attribute/equalsize
you can also use equalsize="always" on the rows as well, this is how it is accomplished in the Thunderbird Lightning calendar layout

DHTMLX: how to put formatting into <afterInit> section in order to have the same result in all browsers?

If I have the following my.xml file:
<rowset>
<head>
<column width="60" hidden="false" type="ro">Col A</column>
<column width="60" hidden="true" type="ro">Col B</column>
<column width="60" hidden="false" type="ro">Col C</column>
<column width="60" hidden="false" type="ro">Col D</column>
<afterInit>
<call command="attachHeader">
<param>A,B,C,D</param>
<param>color:green;,color:red;,color:blue;,color:yellow;</param>
</call>
</afterInit>
</head>
<row id="1">
<cell>value1</cell>
<cell>value2</cell>
<cell>value3</cell>
<cell>value4</cell>
</row>
<row id="2">
<cell>value5</cell>
<cell>value6</cell>
<cell>value7</cell>
<cell>value8</cell>
</row>
<row id="3">
<cell>value-11</cell>
<cell>value-12</cell>
<cell>value-13</cell>
<cell>value-14</cell>
</row>
</rowset>
and the following .html file
<body>
<div id="myGridContainer" width="799px" height="799px"></div>
</body>
<script>
myGrid = new dhtmlXGridObject('myGridContainer');
myGrid.setSkin("xp");
myGrid.xml.top="rowset";
myGrid.attachHeader("A,B,C,D",["color:green","color:red;","color:blue;","color:yellow;"]);
myGrid.load("my.xml");
</script>
then I will receive bad output in Firefox and Chrome. IE works fine. I will create the .xml manually, so I will not use .attachHeader(). But how to create the <afterInit> section with color definitions to have the same result?
Your provided code should work well. If the problem still occurs for you, please provide us a demo link or a complete demo, where the problem can reconstructed.
Instead of <afterInit> should be used <beforeInit>

How to select the node with grand-grandchild node that has particular value

Hi I just want to get the Element A with value of "123abc" in it. I have tried both but failed.
//Package/A[A/B/C/. = 123abc]
//Package/A[contains(A/B/C,123abc)]
I want it to return this:
<A>
<System mtm="8742" os="Windows XP" oslang="en" />
<System mtm="2055" os="Windows XP" oslang="jp" />
<A>
<B>
<C>123abc</C>
<C>789</C>
<C>567</C>
</B>
</A>
</A>
Sample xml to run query on:
<?xml version="1.0" encoding="UTF-8"?>
<Database version="300">
<Package>
<A>
<System mtm="8742" os="Windows XP" oslang="en" />
<System mtm="2055" os="Windows XP" oslang="jp" />
<A>
<B>
<C>123abc</C>
<C>789</C>
<C>567</C>
</B>
</A>
</A>
</Package>
<Package>
<A>
<System mtm="8742" os="Windows XP" oslang="en" />
<System mtm="2055" os="Windows XP" oslang="jp" />
<A>
<B>
<C>efg123</C>
<C>789</C>
<C>567</C>
</B>
</A>
</A>
</Package>
</Database>
You can test your answer here: http://www.freeformatter.com/xpath-tester.html#ad-output
Added the actual xml i am trying to process, but won't work could it be special characters escaped?
actual xml i am trying to process is below, i have tried
//TableSection/SectionItem[SectionItem/Cell/. = "00-18-E7-17-48-64"]
//TableSection/SectionItem[contains(SectionItem/Cell,"00-18-E7-17-48-64")]
<TableSection name="SNMP Devices" IsTreeFormat="true">
<SectionProperties>
<Column id="1" Name="IP Address" />
<Column id="2" Name="Description" />
</SectionProperties>
<SectionItem>
<Cell columnid="1">
192.168.99.54
</Cell>
<Cell columnid="2">
WMI XScan
</Cell>
<SectionItem>
<Cell columnid="1">
ScanType
</Cell>
<Cell columnid="2">
WMIScan
</Cell>
</SectionItem>
<SectionItem>
<Cell columnid="1">
Device description
</Cell>
<Cell columnid="2">
WMI dscription
</Cell>
</SectionItem>
<SectionItem>
<Cell columnid="1">
MACAddress
</Cell>
<Cell columnid="2">
00-18-E7-17-48-64
</Cell>
</SectionItem>
</SectionItem>
<SectionItem>
<Cell columnid="1">
192.168.99.55
</Cell>
<Cell columnid="2">
WMI XScan
</Cell>
<SectionItem>
<Cell columnid="1">
ScanType
</Cell>
<Cell columnid="2">
WMIScan
</Cell>
</SectionItem>
<SectionItem>
<Cell columnid="1">
Device description
</Cell>
<Cell columnid="2">
WMI dscription
</Cell>
</SectionItem>
<SectionItem>
<Cell columnid="1">
MACAddress
</Cell>
<Cell columnid="2">
90-2B-34-64-16-9D
</Cell>
</SectionItem>
</SectionItem>
<SectionItem>
<Cell columnid="1">
192.168.99.107
</Cell>
<Cell columnid="2">
VMWare : "navvms08.Crest.local"
</Cell>
<SectionItem>
<Cell columnid="1">
MACAddress
</Cell>
<Cell columnid="2">
00-07-E9-0D-05-C5
</Cell>
</SectionItem>
<SectionItem>
<Cell columnid="1">
Device identifier
</Cell>
<Cell columnid="2">
1.3.6.1.4.1.6876.4.1
</Cell>
</SectionItem>
<SectionItem>
<Cell columnid="1">
Device name
</Cell>
<Cell columnid="2">
"navvms08.Crest.local"
</Cell>
</SectionItem>
<SectionItem>
<Cell columnid="1">
Device description
</Cell>
<Cell columnid="2">
"VMware ESXi 5.5.0 build-1623387 VMware, Inc. x86_64"
</Cell>
</SectionItem>
</SectionItem>
</TableSection>
In the original sample you need to quote your comparison string. Both of these work:
//Package/A[A/B/C/. = "123abc"]
//Package/A[contains(A/B/C,"123abc")]
The query for the actual XML you're running against should be:
//TableSection/SectionItem[SectionItem/Cell[contains(.,"00-18-E7-17-48-64")]]
The problem with:
//TableSection/SectionItem[SectionItem/Cell/. = "00-18-E7-17-48-64"]
is that the text content must match exactly, while the XML has leading and trailing whitespace.
The problem with:
//TableSection/SectionItem[contains(SectionItem/Cell,"00-18-E7-17-48-64")]
is that contains() only looks in the first SectionItem/Cell within //TableSection/SectionItem instead of any SectionItem/Cell therein to find the text.
For the first example, you have not quoted the string you are comparing against. Also you do not need the additional /. expressions as the node atomizaton rules will be applied for the string comparison anyway.
The XPath //Package/A[A/B/C = "123abc"] will suffice.
If you want to do a partial match against the text content of C then you could use //Package/A[A/B/C/contains(., "123abc")]. You do need the . in this as you want to find an A element that has a C grand-daughter element which contains the text 123abc. The . refers to the current context, which here is an individual C element.
Otherwise, if you did A/B/contains(C, "123abc") you would get a type error as you have multiple C elements and fn:contains cannot operate on a sequence.
For the second example, the example without contains is a whitespace issue, you could fix this by using contains, however your contains tries to operate on a sequence. Instead you should rework it to something like this:
//TableSection/SectionItem[SectionItem/Cell/contains(., "00-18-E7-17-48-64")]

Awk find and replace

I have edited question.
I have xml file (FILE1) that looks like:
<Sector sectorNumber="1">
<Cell cellNumber="1" cellCreated="YES" cellIdentity="" cellRange="35000" numberOfTxBranches="1" hsCodeResourceId="0"/>
<Cell cellNumber="2" cellCreated="YES" cellIdentity="" cellRange="35000" numberOfTxBranches="1" hsCodeResourceId="0"/>
<Cell cellNumber="3" cellCreated="YES" cellIdentity="" cellRange="35000" numberOfTxBranches="1" hsCodeResourceId="0"/>
</Sector>
<Sector sectorNumber="2">
<Cell cellNumber="1" cellCreated="YES" cellIdentity="" cellRange="35000" numberOfTxBranches="1" hsCodeResourceId="0"/>
<Cell cellNumber="2" cellCreated="YES" cellIdentity="" cellRange="35000" numberOfTxBranches="1" hsCodeResourceId="0"/>
<Cell cellNumber="3" cellCreated="YES" cellIdentity="" cellRange="35000" numberOfTxBranches="1" hsCodeResourceId="0"/>
</Sector>
<Sector sectorNumber="3">
<Cell cellNumber="1" cellCreated="YES" cellIdentity="" cellRange="35000" numberOfTxBranches="1" hsCodeResourceId="0"/>
<Cell cellNumber="2" cellCreated="YES" cellIdentity="" cellRange="35000" numberOfTxBranches="1" hsCodeResourceId="0"/>
<Cell cellNumber="3" cellCreated="YES" cellIdentity="" cellRange="35000" numberOfTxBranches="1" hsCodeResourceId="0"/>
</Sector>
and I have another file (FILE2) with input data for this xml file:
Cell11="42921"
Cell12="42925"
Cell13="42928"
Cell21="42922"
Cell22="42926"
Cell23="42929"
Cell31="42923"
Cell32="42927"
Cell33="42920"
What i want to do is, assign to all cellIdentity="" values from FILE2, in order. So it should look like this:
<Sector sectorNumber="1">
<Cell cellNumber="1" cellCreated="YES" cellIdentity="42921" cellRange="35000" numberOfTxBranches="1" hsCodeResourceId="0"/>
<Cell cellNumber="2" cellCreated="YES" cellIdentity="42925" cellRange="35000" numberOfTxBranches="1" hsCodeResourceId="0"/>
<Cell cellNumber="3" cellCreated="YES" cellIdentity="42928" cellRange="35000" numberOfTxBranches="1" hsCodeResourceId="0"/>
</Sector>
<Sector sectorNumber="2">
<Cell cellNumber="1" cellCreated="YES" cellIdentity="42922" cellRange="35000" numberOfTxBranches="1" hsCodeResourceId="0"/>
<Cell cellNumber="2" cellCreated="YES" cellIdentity="42926" cellRange="35000" numberOfTxBranches="1" hsCodeResourceId="0"/>
<Cell cellNumber="3" cellCreated="YES" cellIdentity="42929" cellRange="35000" numberOfTxBranches="1" hsCodeResourceId="0"/>
</Sector>
<Sector sectorNumber="3">
<Cell cellNumber="1" cellCreated="YES" cellIdentity="42923" cellRange="35000" numberOfTxBranches="1" hsCodeResourceId="0"/>
<Cell cellNumber="2" cellCreated="YES" cellIdentity="42927" cellRange="35000" numberOfTxBranches="1" hsCodeResourceId="0"/>
<Cell cellNumber="3" cellCreated="YES" cellIdentity="42920" cellRange="35000" numberOfTxBranches="1" hsCodeResourceId="0"/>
</Sector>
I used the code:
awk 'NR==FNR{FS="=";a[NR]=$2;next}/cell/{c++;FS=OFS;$4="cellIdentity="a[c];}1' FILE2 FILE1
but I get this:
<Sector sectorNumber="1">
<Cell cellNumber "1" cellCreated "YES" cellIdentity cellIdentity= "35000" numberOfTxBranches "1" hsCodeResourceId "0" />
<Cell cellNumber="2" cellCreated="YES" cellIdentity="42925" cellRange="35000" numberOfTxBranches="1" hsCodeResourceId="0" />
<Cell cellNumber="3" cellCreated="YES" cellIdentity="42928" cellRange="35000" numberOfTxBranches="1" hsCodeResourceId="0" />
</Sector>
<Sector sectorNumber="2">
<Cell cellNumber="1" cellCreated="YES" cellIdentity="42922" cellRange="35000" numberOfTxBranches="1" hsCodeResourceId="0" />
<Cell cellNumber="2" cellCreated="YES" cellIdentity="42926" cellRange="35000" numberOfTxBranches="1" hsCodeResourceId="0" />
<Cell cellNumber="3" cellCreated="YES" cellIdentity="42929" cellRange="35000" numberOfTxBranches="1" hsCodeResourceId="0" />
</Sector>
<Sector sectorNumber="3">
<Cell cellNumber="1" cellCreated="YES" cellIdentity="42923" cellRange="35000" numberOfTxBranches="1" hsCodeResourceId="0" />
<Cell cellNumber="2" cellCreated="YES" cellIdentity="42927" cellRange="35000" numberOfTxBranches="1" hsCodeResourceId="0" />
<Cell cellNumber="3" cellCreated="YES" cellIdentity="42920" cellRange="35000" numberOfTxBranches="1" hsCodeResourceId="0" />
</Sector>
so as you can see I have problme with Cellidentitny in first line
<Cell cellNumber "1" cellCreated "YES" cellIdentity cellIdentity= "35000" numberOfTxBranches "1" hsCodeResourceId "0" />
it desn't not set the first line, and all other lines are ok, and I don't know why.
I suggest to do this with a programming language that has XML support instead of awk and bash script.
For example, Python. The code might be a tiny bit longer, but in exchange it won't break your XML file as easily.
So if you want to assign the IDs line-wise, in the order they appear in the text file:
import re
from xml.dom import minidom
from itertools import izip
sector_doc = minidom.parse('sectors.xml')
cells = sector_doc.getElementsByTagName('Cell')
with open('cells.txt', 'r') as cell_file:
lines = cell_file.readlines()
for line, cell in izip(lines, cells):
m = re.search('Cell\d+="([^"]+)"', line)
if m: cell.setAttribute('cellIdentity', m.group(1))
with open('sectors_out.xml', 'wb') as out_file:
sector_doc.writexml(out_file)
Try this:
awk 'FNR==NR
{FS="=";a[NR]=$2;next}
/cell/{c++;FS=OFS;
$4="cellIdentity="a[c];}1' file2 file1
Tested Below:
> cat file1
<Sector sectorNumber="1">
<Cell cellNumber="1" cellCreated="YES" cellIdentity="" cellRange="35000" numberOfTxBranches="1" hsCodeResourceId="0"/>
<Cell cellNumber="2" cellCreated="YES" cellIdentity="" cellRange="35000" numberOfTxBranches="1" hsCodeResourceId="0"/>
<Cell cellNumber="3" cellCreated="YES" cellIdentity="" cellRange="35000" numberOfTxBranches="1" hsCodeResourceId="0"/>
</Sector>
<Sector sectorNumber="2">
<Cell cellNumber="1" cellCreated="YES" cellIdentity="" cellRange="35000" numberOfTxBranches="1" hsCodeResourceId="0"/>
<Cell cellNumber="2" cellCreated="YES" cellIdentity="" cellRange="35000" numberOfTxBranches="1" hsCodeResourceId="0"/>
<Cell cellNumber="3" cellCreated="YES" cellIdentity="" cellRange="35000" numberOfTxBranches="1" hsCodeResourceId="0"/>
</Sector>
<Sector sectorNumber="3">
<Cell cellNumber="1" cellCreated="YES" cellIdentity="" cellRange="35000" numberOfTxBranches="1" hsCodeResourceId="0"/>
<Cell cellNumber="2" cellCreated="YES" cellIdentity="" cellRange="35000" numberOfTxBranches="1" hsCodeResourceId="0"/>
<Cell cellNumber="3" cellCreated="YES" cellIdentity="" cellRange="35000" numberOfTxBranches="1" hsCodeResourceId="0"/>
</Sector>
> cat file2
Cell11="42921"
Cell12="42925"
Cell13="42928"
Cell21="42922"
Cell22="42926"
Cell23="42929"
Cell31="42923"
Cell32="42927"
Cell33="42920"
> awk 'FNR==NR{FS="=";a[NR]=$2;next}/cell/{c++;FS=OFS;$4="cellIdentity="a[c];}1' file2 file1
<Sector sectorNumber="1">
<Cell cellNumber="1" cellCreated="YES" cellIdentity="42921" cellRange="35000" numberOfTxBranches="1" hsCodeResourceId="0"/>
<Cell cellNumber="2" cellCreated="YES" cellIdentity="42925" cellRange="35000" numberOfTxBranches="1" hsCodeResourceId="0"/>
<Cell cellNumber="3" cellCreated="YES" cellIdentity="42928" cellRange="35000" numberOfTxBranches="1" hsCodeResourceId="0"/>
</Sector>
<Sector sectorNumber="2">
<Cell cellNumber="1" cellCreated="YES" cellIdentity="42922" cellRange="35000" numberOfTxBranches="1" hsCodeResourceId="0"/>
<Cell cellNumber="2" cellCreated="YES" cellIdentity="42926" cellRange="35000" numberOfTxBranches="1" hsCodeResourceId="0"/>
<Cell cellNumber="3" cellCreated="YES" cellIdentity="42929" cellRange="35000" numberOfTxBranches="1" hsCodeResourceId="0"/>
</Sector>
<Sector sectorNumber="3">
<Cell cellNumber="1" cellCreated="YES" cellIdentity="42923" cellRange="35000" numberOfTxBranches="1" hsCodeResourceId="0"/>
<Cell cellNumber="2" cellCreated="YES" cellIdentity="42927" cellRange="35000" numberOfTxBranches="1" hsCodeResourceId="0"/>
<Cell cellNumber="3" cellCreated="YES" cellIdentity="42920" cellRange="35000" numberOfTxBranches="1" hsCodeResourceId="0"/>
</Sector>
>

Resources