Limit maximun records selected in grid detail list

Hi team ,

I have a case where is required not select more than 5 records in the list. How can prevent the section of more records in a expandable list?

expandable lixt

Like 0

Like

5 comments
Best reply

Federico Buffa 🧐,

Try this Handler:
[
		 {
  request: "qnt.PDFButton",
  handler: async (request, next) => {
    const selectionState = await request.$context.DataGrid_v9rpzfx_SelectionState;
    let selectedIds = selectionState.selected;
 
    if (!selectedIds || selectedIds.length === 0) {
      crt.ShowMessage("Please select at least one record.");
      return;
    }
 
    if (selectedIds.length > 3) {
      // Trim the selection to the first 3
      const trimmedIds = selectedIds.slice(0, 3);
			console.log("TrimmedId",trimmedIds);
 
      selectionState.selected = trimmedIds;
		request.$context.executeRequest({
    type: "crt.LoadDataRequest",
    $context: request.$context,
    config: {
        loadType: "reload",
        useLastLoadParameters: true
    },
    dataSourceName: "DataGrid_v9rpzfxDS"
});
    }
 
		      return next?.handle(request);
		    }
		  }
		]
const selectionState = await request.$context.DataGrid_v9rpzfx_SelectionState;
 
  const selectedIds = selectionState.selected;
 
  if (!selectedIds || selectedIds.length === 0) {
   console.log("Please select at least one record.");
    return;
  }
 
  if (selectedIds.length > 3) {
    console.log("You can select a maximum of 3 records only.");
    return;
  }

use this code sniper

Thank you Smit!

smit suthar,

Do you know if there is any way to unselect the record from the grid automatically?

Federico Buffa 🧐,

Try this Handler:
[
		 {
  request: "qnt.PDFButton",
  handler: async (request, next) => {
    const selectionState = await request.$context.DataGrid_v9rpzfx_SelectionState;
    let selectedIds = selectionState.selected;
 
    if (!selectedIds || selectedIds.length === 0) {
      crt.ShowMessage("Please select at least one record.");
      return;
    }
 
    if (selectedIds.length > 3) {
      // Trim the selection to the first 3
      const trimmedIds = selectedIds.slice(0, 3);
			console.log("TrimmedId",trimmedIds);
 
      selectionState.selected = trimmedIds;
		request.$context.executeRequest({
    type: "crt.LoadDataRequest",
    $context: request.$context,
    config: {
        loadType: "reload",
        useLastLoadParameters: true
    },
    dataSourceName: "DataGrid_v9rpzfxDS"
});
    }
 
		      return next?.handle(request);
		    }
		  }
		]
Show all comments