Guest User

Untitled

a guest
Jul 22nd, 2018
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.20 KB | None | 0 0
  1. import React from 'react';
  2. import ReactDOM from 'react-dom';
  3. import $ from 'jquery';
  4. import kendo from '@progress/kendo-ui';
  5. import { Grid, GridColumn } from '@progress/kendo-grid-react-wrapper';
  6. import { DropDownList } from '@progress/kendo-react-dropdowns';
  7. import { GridCell } from '@progress/kendo-react-grid';
  8.  
  9.  
  10. class DropDownCell extends GridCell {
  11. handleChange(e) {
  12. this.props.onChange({
  13. dataItem: this.props.dataItem,
  14. field: this.props.field,
  15. syntheticEvent: e.syntheticEvent,
  16. value: e.target.value
  17. });
  18. }
  19. render() {
  20. const value = this.props.dataItem[this.props.field];
  21.  
  22. if (!this.props.dataItem.inEdit) {
  23. return (
  24. <td> {
  25. (value === null) ? '' : this.props.dataItem[this.props.field].toString()}
  26. </td>
  27. );
  28. }
  29.  
  30. return (
  31. <td>
  32. <DropDownList
  33. style={{ width: "100px" }}
  34. onChange={this.handleChange.bind(this)}
  35. value={value}
  36. data={[
  37. { text: 'yes', value: true },
  38. { text: 'no', value: false },
  39. { text: '(empty)', value: null }
  40. ]}
  41. valueField="value"
  42. textField="text"
  43. />
  44. </td>
  45. );
  46. }
  47. }
  48.  
  49. class AppComponent extends React.Component{
  50. constructor(props){
  51. super(props);
  52.  
  53. this.onDataBound = function(){
  54. $(".toolbar").html(
  55. `<tr>
  56. <td>
  57. </tr>`
  58. );
  59. }
  60.  
  61. this.state = {
  62. products :[
  63. { ProductID: 1,ProductName: "Chai",SupplierID: 1,CategoryID: 1,QuantityPerUnit: "10 boxes x 20 bags",UnitPrice: 18.0000,UnitsInStock: 39,UnitsOnOrder: 0,ReorderLevel: 10,Discontinued: false,Category: { CategoryID: 1,CategoryName: "Beverages",Description: "Soft drinks, coffees, teas, beers, and ales"}},
  64. { ProductID: 2,ProductName: "Chang",SupplierID: 1,CategoryID: 1,QuantityPerUnit: "24 - 12 oz bottles",UnitPrice: 19.0000,UnitsInStock: 17,UnitsOnOrder: 40,ReorderLevel: 25,Discontinued: false,Category: {CategoryID: 1,CategoryName: "Beverages",Description: "Soft drinks, coffees, teas, beers, and ales"}},
  65. {ProductID: 3,ProductName: "Aniseed Syrup",SupplierID: 1,CategoryID: 2,QuantityPerUnit: "12 - 550 ml bottles",UnitPrice: 10.0000,UnitsInStock: 13,UnitsOnOrder: 35,ReorderLevel: 25,Discontinued: false,Category: {CategoryID: 2,CategoryName: "Condiments",Description: "Sweet and savory sauces, relishes, spreads, and seasonings"}},
  66. {ProductID: 4,ProductName: "Chef Anton's Cajun Seasoning",SupplierID: 2,CategoryID: 2,QuantityPerUnit: "48 - 6 oz jars",UnitPrice: 22.0000,UnitsInStock: 53,UnitsOnOrder: 0,ReorderLevel: 0,Discontinued: false,Category: {CategoryID: 2,CategoryName: "Condiments",Description: "Sweet and savory sauces, relishes, spreads, seasonings"}},
  67. {ProductID: 5,ProductName: "Chef Anton's Gumbo Mix",SupplierID: 2,CategoryID: 2,QuantityPerUnit: "36 boxes",UnitPrice: 21.3500,UnitsInStock: 0,UnitsOnOrder: 0,ReorderLevel: 0,Discontinued: true,Category: {CategoryID: 2,CategoryName: "Condiments",Description: "Sweet and savory sauces, relishes, spreads, and seasonings"}},
  68. {ProductID: 6,ProductName: "Grandma's Boysenberry Spread",SupplierID: 3,CategoryID: 2,QuantityPerUnit: "12 - 8 oz jars",UnitPrice: 25.0000,UnitsInStock: 120,UnitsOnOrder: 0,ReorderLevel: 25,Discontinued: false,Category: {CategoryID: 2,CategoryName: "Condiments",Description: "Sweet and savory sauces, relishes, spreads, seasonings"}},
  69. {ProductID: 7,ProductName: "Uncle Bob's Organic Dried Pears",SupplierID: 3,CategoryID: 7,QuantityPerUnit: "12 - 1 lb pkgs.",UnitPrice: 30.0000,UnitsInStock: 15,UnitsOnOrder: 0,ReorderLevel: 10,Discontinued: false,Category: {CategoryID: 7,CategoryName: "Produce",Description: "Dried fruit and bean curd"}},
  70. {ProductID: 8,ProductName: "Northwoods Cranberry Sauce",SupplierID: 3,CategoryID: 2,QuantityPerUnit: "12 - 12 oz jars",UnitPrice: 40.0000,UnitsInStock: 6,UnitsOnOrder: 0,ReorderLevel: 0,Discontinued: false,Category: {CategoryID: 2,CategoryName: "Condiments",Description: "Sweet and savory sauces, relishes, spreads, seasonings"}},
  71. {ProductID: 9,ProductName: "Mishi Kobe Niku",SupplierID: 4,CategoryID: 6,QuantityPerUnit: "18 - 500 g pkgs.",UnitPrice: 97.0000,UnitsInStock: 29,UnitsOnOrder: 0,ReorderLevel: 0,Discontinued: true,Category: {CategoryID: 6,CategoryName: "Meat/Poultry",Description: "Prepared meats"}},
  72. {ProductID: 10,ProductName: "Ikura",SupplierID: 4,CategoryID: 8,QuantityPerUnit: "12 - 200 ml jars",UnitPrice: 31.0000,UnitsInStock: 31,UnitsOnOrder: 0,ReorderLevel: 0,Discontinued: false,Category: {CategoryID: 8,CategoryName: "Seafood",Description: "Seaweed and fish"}}
  73. ]
  74. };
  75.  
  76. this.dataSource = new kendo.data.DataSource({
  77. data: this.state.products,
  78. pageSize: 5,
  79. schema:{
  80. model:{
  81. field:{
  82. ProductID: {type:"number"},
  83. ProductName:{type:"string"},
  84. Discontinued:{type:"boolean"}
  85.  
  86. }
  87. }
  88. }
  89. });
  90. }
  91.  
  92. render(){
  93. return(
  94. <div>
  95. <Grid
  96. dataSource={this.dataSource}
  97. filterable={true}
  98. editable={true }
  99. sortable={true}
  100. pageable={true}
  101. groupable={true}
  102. editable={"inline"}
  103. dataBound={this.onDataBound}>
  104. <GridColumn field="Discontinued" title="Discontinued" cell={DropDownCell} />
  105. <GridColumn field="SupplierID" title="Supperlie Id"/>
  106. <GridColumn field="CategoryID" title="Category Id"/>
  107. <GridColumn field="QuantityPerUnit" title="Quantity Per Unit"/>
  108. <GridColumn command={["edit", "destroy"]} title="&nbsp;" width="200px" />
  109. </Grid>
  110. </div>
  111. )
  112. }
  113. }
  114.  
  115. export default AppComponent;
Add Comment
Please, Sign In to add comment