Selecting rows with PersistSelection

Hi there,

I'm using SyncFusion Grid with serverside data binding.
When I enable PersistSelection option, getSelectedRecords() method returns null.
How can I fix that?

Thanks
Masoud


1 Reply

RR Rajapandi Ravi Syncfusion Team May 5, 2020 01:04 PM UTC

Hi Masoud, 

Greetings from syncfusion support 

You can achieve your requirement by using rowSelected event of Grid. In selection settings, if you are setting the persistSelection as true then you have to define any one of the column should be enabled as a primary key. Please refer the below code example and sample for more information. 

 
<template> 
  <div id="app"> 
    <ejs-grid 
      :dataSource="data" 
      :rowSelected="rowSelected" 
      :selectionSettings="selectionOptions" 
      :allowFiltering="true" 
    > 
      <e-columns> 
        <e-column field="OrderID" headerText="Order ID" isPrimaryKey="true" textAlign="Right" width="90"></e-column> 
        <e-column field="CustomerID" headerText="Customer ID" width="120"></e-column> 
        <e-column field="Freight" headerText="Freight" textAlign="Right" format="C2" width="90"></e-column> 
        <e-column 
          field="OrderDate" 
          headerText="Order Date" 
          textAlign="Right" 
          format="yMd" 
          type="date" 
          width="120" 
        ></e-column> 
     </e-columns> 
    </ejs-grid> 
  </div> 
</template> 
<script> 
import Vue from "vue"; 
import { GridPlugin, Filter } from "@syncfusion/ej2-vue-grids"; 
import { DataManager, ODataAdaptor } from "@syncfusion/ej2-data"; 
 
Vue.use(GridPlugin); 
 
class SerialNoAdaptor extends ODataAdaptor { 
  onPredicate(predicate, query, requiresCast) { 
    predicate.value = predicate.value.toLowerCase(); 
    var returnvalue = super.onPredicate.call( 
      this, 
      predicate, 
      query, 
      requiresCast 
    ); 
 
    return decodeURIComponent(returnvalue); 
  } 
} 
 
export default { 
  data() { 
    let SERVICE_URI = 
    return { 
      data: new DataManager({ 
        url: SERVICE_URI, 
        adaptor: new SerialNoAdaptor(), 
        crossDomain: true 
      }), 
      selectionOptions: { 
        type: "Multiple", 
        persistSelection: true 
      } 
    }; 
  }, 
  methods: { 
    rowSelected: function(args) { 
      var grid = document.getElementsByClassName("e-grid")[0].ej2_instances[0];  //Grid instance 
      var selctedrecord =  grid.getSelectedRecords()[0];    //Get the selected records 
      console.log(selctedrecord); 
    } 
  }, 
  provide: { 
    grid: [Filter] 
  } 
}; 
</script> 
<style> 
</style> 


Note: By default selection is allowed by clicking a grid row or checkbox in that row. To allow Selection only through checkbox, you can set selectionSettings.checkboxOnly property to true. Selection can be persisted on all the operations using selectionSettings.persistSelection property. For persisting selection on the Grid, any one of the column should be defined as a primary key using columns.isPrimaryKey property. 


Regards, 
Rajapandi R

Loader.
Up arrow icon