How to set column freezing and styling in a ListView?

// In custom scripts, the list view can add practical features
// 1. Allow setting which column index to start freezing properties from, similar to Excel's frozen columns (as shown in the figure)

// 2. Column style definitions: such as text color, background color
// 2.1 Example 1: When a column's value is greater than 1000, set this column's font to blue bold, or red italic
// 2.2 Example 2: When a column's value is greater than 10000, set the column's background color to red and font color to white

function XSetColumnStyle(listname, cid, color) {

	// Custom utility function: get control object
	var listView = $.xctrl(listname);	
	//var listView = DOpus.Dlg.Control(listname);
	
	if(listView && listView.mode === "details"){

		// Get selected row data
		// var listItem = listView.Value;

		// Get total number of rows in the list
		var count = listView.count;
		
		// Custom utility function: get object type and log output
		//$.xtype(listView, listItem);
		//$.xlog(listView.count, listItem.fg);


		// Iterate over all row and column objects in the list
		for(var i = 0; i < count; i++){
			var row = listView.GetItemAt(i);

			// Get the column object corresponding to the row (this is pseudocode)
			var colobj = row.columns(cid);

			// Get the subitem's value
			var column = row.subitems(cid);
			if(column > 1000){

				// The following are three simulated implementation methods; in reality, they do not exist (this is pseudocode)
			
				// 1. Set the column style through the "attr" method (batch configuration)
				colobj.attr({"color": color, "bold": true, "italic": true});
				if(column > 10000){
					colobj.attr({
						"background": "#FF0000",
						"color": "#FFFFFF"
					});
				}

				// 2. Set the column style through the "style" method (set individual styles each time)
				//colobj.style("color", color); // style("bold", true);
				
				// 3. Modify the column style using "markuptext" format (allows for more complex styling extensions, such as links, but cannot set column background color)
				//colobj.value('<b><font color="#FF0000">'+ column +'</font></b>');
				//row.subitems(cid) = '<b><font color="#FF0000">'+ column +'</font></b>';
			}
		}
	}
}

Please link your account.

It has been added.
Is there a development plan to implement the feature requirements mentioned above

Hello, will the functions described above be launched in the next version? Thank you.

In 13.12.1 we'll add the ability to configure colors and font styles for individual subitems.

1 Like

Thank you very much, @Jon . I found that the function has been added. I just updated to the latest v13.12.2 beta version and the feedback on the test issues is as follows.

// Normal operation and expected effect
var subitem = listview.GetItemAt(1).subitems("3");

// Sub-item assignment, normal
subitem.text = "Yes";

// Set the font bold style to achieve the desired effect
subitem.style("b");

// Setting the background/foreground of the sub-item is invalid and cannot achieve the expected effect
subitem.bg("#FFCA28");
// subitem.bg = "#FFCA28";
// subitem.fg("#FFCA28");

Operating version: v13.12.2
Test environment: win10 21H2 19044.2130

I think those are properties and not methods, so you should use them as you do with .text above.
(Btw there is no mention of such property existing)

There's a bug in the Windows listview control we forgot about, so a change in 13.12.2 broke this. Should work again in 13.12.3.

Version transfer link:v13.12.1 beta

Thank you for the correction. The official documentation indeed does not provide this .text property. It's strange that no error was reported when using this property. I hope it doesn't mislead others.

Changes in betas aren't always in the documentation until the stable release.

But it's documented here now: DialogListSubItem [Directory Opus Manual]