Two Data Loading Methods for Script Button Dialog View Lists

Current official implementation for list view data loading requires at least two iterations to complete full data population. For basic list data rendering, manually iterating through each row/column for value assignment is fundamentally redundant. We recommend the framework team optimize view list data binding mechanisms with batch processing capabilities. :slightly_smiling_face:

function loadListView(){
	var listView = $.xdlg.Control("listview1");
	var dataList = $.getDataList();
	try{
		// 第一种:视图列表批量加载多行数据绑定,只需一行代码
		// Option 1: Implement batch data loading for list views with a single-line solution.
		listView.data = dataList;
		// return true;

		for(var i = 0; i < dataList.length; i++){
			var rdata = dataList[i];
			var items = listView.GetItemAt(listView.AddItem(rdata[0]));

			// 第二种:视图列表加载单行数据,禁止使用循环
			// Option 2: Implement single-row data binding for list views using declarative patterns (loop-free approach).
			items.subitems = rdata;

			// 原始数据加载方式,需要循环 N 次
			// With the original data loading method, it is necessary to perform N loops.
			/*
			for(var d = 1; d < rdata.length; d++){
				//$.xlog(rdata[d]);
				items.subitems(d-1) = rdata[d];
			}
			*/
			var cell3 = items.subitems(2);
			if(String(cell3).search("/08/") > 0){
				cell3.fg("#3099ff");
				cell3.styles("u", "b");
				//cell3.styles("b", "i", "u");
				//cell3.styles("u");
			}
			var cell5 = items.subitems(4);
			//$.xlog(cell5);
			if(Number(cell5) > 2000){
				cell5.fg("#FFFFFF");
				cell5.bg("#FF0000");
				cell5.styles("b");
			}
		}
		listView.columns.AutoSize();
	}catch(err){
		$.xlog("error message: " + err.message);
	}
}

function getDataList(){
	var datas = [
		[1001, "PRO-SHA", "UW-F20-10", "2005/07/01", "45.2", "1500", "N", "200", "v1.3.13"],
		[2001, "PRO-SHA", "UW-F20-11", "2006/06/12", "40.23", "2343", "Y", "343", "v2.5.1"],
		[3001, "PRO-SHA", "UW-F20-12", "2006/08/20", "53.39", "1120", "Y", "90", "v1.4.22"],
		[4001, "PRO-SHB", "UW-K45-S4", "2007/05/23", "58.9", "300", "N", "10", "v2.8.0"],
		[5001, "PRO-SHB", "UW-K09-G5", "2008/03/13", "60.33", "532", "Y", "20", "v4.6.1"],
		[6001, "PRO-SHB", "UW-K21-R3", "2008/09/14", "64.78", "1430", "N", "180", "v1.1.19"],
		[7001, "PRO-SHC", "UW-J33-56", "2010/04/28", "67.45", "2800", "Y", "520", "v7.12.04"],
		[8001, "PRO-SHC", "UW-J52-24", "2011/08/19", "70.49", "3740", "Y", "940", "v9.15.08"],
		[9001, "PRO-SHC", "UW-J63-39", "2013/01/04", "70.14", "5999", "Y", "1260", "v11.9.03"],
		[10001, "PRO-SHC", "UW-J89-75", "2013/11/16", "67.78", "7810", "Y", "2790", "v11.12.03"]
	];
	return datas;
}

I don't know if it is very difficult to implement this functional requirement or what. There is no reply. My demand is very simple, that is, to simplify complex logic. Thanks.

var listView = DOpus.Dlg.Control("listview1");

// 1.Batch binding of view list data
listView.data = [
		[1001, "PRO-SHA", "UW-F20-10", "2005/07/01", "45.2", "1500", "N", "200", "v1.3.13"],
		[2001, "PRO-SHA", "UW-F20-11", "2006/06/12", "40.23", "2343", "Y", "343", "v2.5.1"],
		[3001, "PRO-SHA", "UW-F20-12", "2006/08/20", "53.39", "1120", "Y", "90", "v1.4.22"],
		[4001, "PRO-SHB", "UW-K45-S4", "2007/05/23", "58.9", "300", "N", "10", "v2.8.0"],
		[5001, "PRO-SHB", "UW-K09-G5", "2008/03/13", "60.33", "532", "Y", "20", "v4.6.1"],
		[6001, "PRO-SHB", "UW-K21-R3", "2008/09/14", "64.78", "1430", "N", "180", "v1.1.19"],
		[7001, "PRO-SHC", "UW-J33-56", "2010/04/28", "67.45", "2800", "Y", "520", "v7.12.04"],
		[8001, "PRO-SHC", "UW-J52-24", "2011/08/19", "70.49", "3740", "Y", "940", "v9.15.08"],
		[9001, "PRO-SHC", "UW-J63-39", "2013/01/04", "70.14", "5999", "Y", "1260", "v11.9.03"],
		[10001, "PRO-SHC", "UW-J89-75", "2013/11/16", "67.78", "7810", "Y", "2790", "v11.12.03"]
	];

// 2. Or single-row binding of view list data (automatically bound according to the array and column index)
var subitems = listView.GetItemAt(listView.AddItem("1"));
subitems = [2001, "PRO-SHA", "UW-F20-11", "2006/06/12", "40.23", "2343", "Y", "343", "v2.5.1"];

While I agree the way adding items with subitems to listviews could be enhanced (since, most of the time, we'll already have structured data for items and subitems ready when building the listview content), I'm not sure this will go on top of the list.

There might be items with higher priorities (bugs and other features that are currently under development, such as the FTP/SFTP code rewrite which is in progress and awaited by some users for quite some time) since there is no show stopper here : you can achieve what you want with code which readability could be improved but that is still largely understandable.

This could be the reason for the lack of answer in 3 days (which is not that much actually).

Thanks for your answer. I mistakenly thought that my question was not described clearly

We've added this in the next beta. Thanks for the suggestion!

Yes they added it, and it works great.

For instance I changed it in one of my scripts, to add all columns at once:

if (groupId) {
	listIx = Listview.AddItem([fname,fext,stat,color,newfol,fpath], 0, groupId);
} else {
	listIx = Listview.AddItem([fname,fext,stat,color,newfol,fpath]);
}

(I kept the “listIx” though, because I also need to add an icon - and this can’t be done in one move afaics).

And, although not yet tested, it should be possible to add multiple lines x multiple columns by using a 2-dimensional array (or an Opus vector).

This improvement is long overdue.